Probably broke Win7 Tests (dbg)(6). http://build.chromium.org/p/chromium.win/builders...
[chromium-blink-merge.git] / net / proxy / proxy_resolver_script_data.h
blob16e17fd529320f6b7c068bdd652756678e23ef09
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.
5 #ifndef NET_PROXY_PROXY_RESOLVER_SCRIPT_DATA_H_
6 #define NET_PROXY_PROXY_RESOLVER_SCRIPT_DATA_H_
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"
13 namespace net {
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.
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,
30 // Creates a script data given the UTF8 bytes of the content.
31 static scoped_refptr<ProxyResolverScriptData> FromUTF8(
32 const std::string& utf8);
34 // Creates a script data given the UTF16 bytes of the content.
35 static scoped_refptr<ProxyResolverScriptData> FromUTF16(
36 const base::string16& utf16);
38 // Creates a script data given a URL to the PAC script.
39 static scoped_refptr<ProxyResolverScriptData> FromURL(const GURL& url);
41 // Creates a script data for using an automatically detected PAC URL.
42 static scoped_refptr<ProxyResolverScriptData> ForAutoDetect();
44 Type type() const {
45 return type_;
48 // Returns the contents of the script as UTF16.
49 // (only valid for type() == TYPE_SCRIPT_CONTENTS).
50 const base::string16& utf16() const;
52 // Returns the URL of the script.
53 // (only valid for type() == TYPE_SCRIPT_URL).
54 const GURL& url() const;
56 // Returns true if |this| matches |other|.
57 bool Equals(const ProxyResolverScriptData* other) const;
59 private:
60 friend class base::RefCountedThreadSafe<ProxyResolverScriptData>;
61 ProxyResolverScriptData(Type type,
62 const GURL& url,
63 const base::string16& utf16);
64 virtual ~ProxyResolverScriptData();
67 const Type type_;
68 const GURL url_;
69 const base::string16 utf16_;
72 } // namespace net
74 #endif // NET_PROXY_PROXY_RESOLVER_SCRIPT_DATA_H_