1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_PROXY_RESOLUTION_PAC_FILE_DATA_H_ 6 #define NET_PROXY_RESOLUTION_PAC_FILE_DATA_H_ 7 8 #include <string> 9 10 #include "base/memory/ref_counted.h" 11 #include "net/base/net_export.h" 12 #include "url/gurl.h" 13 14 namespace net { 15 16 // Reference-counted wrapper for passing around a PAC script specification. 17 // The PAC script can be either specified via a URL, a deferred URL for 18 // auto-detect, or the actual javascript program text. 19 // 20 // This is thread-safe so it can be used by multi-threaded implementations of 21 // ProxyResolver to share the data between threads. 22 class NET_EXPORT_PRIVATE PacFileData 23 : public base::RefCountedThreadSafe<PacFileData> { 24 public: 25 enum Type { 26 TYPE_SCRIPT_CONTENTS, 27 TYPE_SCRIPT_URL, 28 TYPE_AUTO_DETECT, 29 }; 30 31 // Creates a script data given the UTF8 bytes of the content. 32 static scoped_refptr<PacFileData> FromUTF8(const std::string& utf8); 33 34 // Creates a script data given the UTF16 bytes of the content. 35 static scoped_refptr<PacFileData> FromUTF16(const std::u16string& utf16); 36 37 // Creates a script data given a URL to the PAC script. 38 static scoped_refptr<PacFileData> FromURL(const GURL& url); 39 40 // Creates a script data for using an automatically detected PAC URL. 41 static scoped_refptr<PacFileData> ForAutoDetect(); 42 type()43 Type type() const { return type_; } 44 45 // Returns the contents of the script as UTF16. 46 // (only valid for type() == TYPE_SCRIPT_CONTENTS). 47 const std::u16string& utf16() const; 48 49 // Returns the URL of the script. 50 // (only valid for type() == TYPE_SCRIPT_URL). 51 const GURL& url() const; 52 53 // Returns true if |this| matches |other|. 54 bool Equals(const PacFileData* other) const; 55 56 private: 57 friend class base::RefCountedThreadSafe<PacFileData>; 58 PacFileData(Type type, const GURL& url, const std::u16string& utf16); 59 virtual ~PacFileData(); 60 61 const Type type_; 62 const GURL url_; 63 const std::u16string utf16_; 64 }; 65 66 } // namespace net 67 68 #endif // NET_PROXY_RESOLUTION_PAC_FILE_DATA_H_ 69