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/string16.h"
10 #include "googleurl/src/gurl.h"
11 #include "net/base/net_export.h"
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
> {
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 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();
48 // Returns the contents of the script as UTF16.
49 // (only valid for type() == TYPE_SCRIPT_CONTENTS).
50 const 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;
60 friend class base::RefCountedThreadSafe
<ProxyResolverScriptData
>;
61 ProxyResolverScriptData(Type type
,
63 const string16
& utf16
);
64 virtual ~ProxyResolverScriptData();
69 const string16 utf16_
;
74 #endif // NET_PROXY_PROXY_RESOLVER_SCRIPT_DATA_H_