1 // Copyright (c) 2010 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 #include "net/proxy/proxy_resolver_script_data.h"
6
7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h"
9
10 namespace net {
11
12 // static
FromUTF8(const std::string & utf8)13 scoped_refptr<ProxyResolverScriptData> ProxyResolverScriptData::FromUTF8(
14 const std::string& utf8) {
15 return new ProxyResolverScriptData(TYPE_SCRIPT_CONTENTS,
16 GURL(),
17 UTF8ToUTF16(utf8));
18 }
19
20 // static
FromUTF16(const string16 & utf16)21 scoped_refptr<ProxyResolverScriptData> ProxyResolverScriptData::FromUTF16(
22 const string16& utf16) {
23 return new ProxyResolverScriptData(TYPE_SCRIPT_CONTENTS, GURL(), utf16);
24 }
25
26 // static
FromURL(const GURL & url)27 scoped_refptr<ProxyResolverScriptData> ProxyResolverScriptData::FromURL(
28 const GURL& url) {
29 return new ProxyResolverScriptData(TYPE_SCRIPT_URL, url, string16());
30 }
31
32 // static
33 scoped_refptr<ProxyResolverScriptData>
ForAutoDetect()34 ProxyResolverScriptData::ForAutoDetect() {
35 return new ProxyResolverScriptData(TYPE_AUTO_DETECT, GURL(), string16());
36 }
37
utf16() const38 const string16& ProxyResolverScriptData::utf16() const {
39 DCHECK_EQ(TYPE_SCRIPT_CONTENTS, type_);
40 return utf16_;
41 }
42
url() const43 const GURL& ProxyResolverScriptData::url() const {
44 DCHECK_EQ(TYPE_SCRIPT_URL, type_);
45 return url_;
46 }
47
ProxyResolverScriptData(Type type,const GURL & url,const string16 & utf16)48 ProxyResolverScriptData::ProxyResolverScriptData(Type type,
49 const GURL& url,
50 const string16& utf16)
51 : type_(type),
52 url_(url),
53 utf16_(utf16) {
54 }
55
~ProxyResolverScriptData()56 ProxyResolverScriptData::~ProxyResolverScriptData() {}
57
58 } // namespace net
59