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