1// Copyright (c) 2011 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#pragma once 8 9#include "base/memory/ref_counted.h" 10#include "base/string16.h" 11#include "googleurl/src/gurl.h" 12 13namespace 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. 21class 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 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 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 private: 57 friend class base::RefCountedThreadSafe<ProxyResolverScriptData>; 58 ProxyResolverScriptData(Type type, 59 const GURL& url, 60 const string16& utf16); 61 virtual ~ProxyResolverScriptData(); 62 63 64 const Type type_; 65 const GURL url_; 66 const string16 utf16_; 67}; 68 69} // namespace net 70 71#endif // NET_PROXY_PROXY_RESOLVER_SCRIPT_DATA_H_ 72