Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(797)

Side by Side Diff: chrome/browser/extensions/api/dns/dns_api.cc

Issue 9600050: Add IDL capability to json_schema_compiler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Set 1 Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/dns/dns_api.h" 5 #include "chrome/browser/extensions/api/dns/dns_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/io_thread.h" 10 #include "chrome/browser/io_thread.h"
11 #include "chrome/common/extensions/api/experimental.dns.h"
asargent_no_longer_on_chrome 2012/03/06 22:27:57 This experimental.dns.h file gets auto-generated d
miket_OOO 2012/03/07 00:23:01 Don't worry! If you take a look at http://coderevi
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "net/base/host_port_pair.h" 13 #include "net/base/host_port_pair.h"
13 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
14 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
15 16
16 using content::BrowserThread; 17 using content::BrowserThread;
18 using namespace extensions::api::experimental;
17 19
18 namespace extensions { 20 namespace extensions {
19 21
20 const char kAddressKey[] = "address";
21 const char kResultCodeKey[] = "resultCode";
22
23 // static 22 // static
24 net::HostResolver* DNSResolveFunction::host_resolver_for_testing; 23 net::HostResolver* DNSResolveFunction::host_resolver_for_testing;
25 24
26 DNSResolveFunction::DNSResolveFunction() 25 DNSResolveFunction::DNSResolveFunction()
27 : response_(false), 26 : response_(false),
28 io_thread_(g_browser_process->io_thread()), 27 io_thread_(g_browser_process->io_thread()),
29 capturing_bound_net_log_(new net::CapturingBoundNetLog( 28 capturing_bound_net_log_(new net::CapturingBoundNetLog(
30 net::CapturingNetLog::kUnbounded)), 29 net::CapturingNetLog::kUnbounded)),
31 request_handle_(new net::HostResolver::RequestHandle()), 30 request_handle_(new net::HostResolver::RequestHandle()),
32 addresses_(new net::AddressList) { 31 addresses_(new net::AddressList) {
33 } 32 }
34 33
35 DNSResolveFunction::~DNSResolveFunction() { 34 DNSResolveFunction::~DNSResolveFunction() {
36 } 35 }
37 36
38 // static 37 // static
39 void DNSResolveFunction::set_host_resolver_for_testing( 38 void DNSResolveFunction::set_host_resolver_for_testing(
40 net::HostResolver* host_resolver_for_testing_param) { 39 net::HostResolver* host_resolver_for_testing_param) {
41 host_resolver_for_testing = host_resolver_for_testing_param; 40 host_resolver_for_testing = host_resolver_for_testing_param;
42 } 41 }
43 42
44 bool DNSResolveFunction::RunImpl() { 43 bool DNSResolveFunction::RunImpl() {
45 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &hostname_)); 44 scoped_ptr<Resolve::Params> params(Resolve::Params::Create(*args_));
45 EXTENSION_FUNCTION_VALIDATE(params.get());
46
47 hostname_ = params->hostname;
48
46 bool result = BrowserThread::PostTask( 49 bool result = BrowserThread::PostTask(
47 BrowserThread::IO, FROM_HERE, 50 BrowserThread::IO, FROM_HERE,
48 base::Bind(&DNSResolveFunction::WorkOnIOThread, this)); 51 base::Bind(&DNSResolveFunction::WorkOnIOThread, this));
49 DCHECK(result); 52 DCHECK(result);
50 return true; 53 return true;
51 } 54 }
52 55
53 void DNSResolveFunction::WorkOnIOThread() { 56 void DNSResolveFunction::WorkOnIOThread() {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
55 58
(...skipping 14 matching lines...) Expand all
70 request_handle_.get(), capturing_bound_net_log_->bound()); 73 request_handle_.get(), capturing_bound_net_log_->bound());
71 74
72 // Balanced in OnLookupFinished. 75 // Balanced in OnLookupFinished.
73 AddRef(); 76 AddRef();
74 77
75 if (resolve_result != net::ERR_IO_PENDING) 78 if (resolve_result != net::ERR_IO_PENDING)
76 OnLookupFinished(resolve_result); 79 OnLookupFinished(resolve_result);
77 } 80 }
78 81
79 void DNSResolveFunction::OnLookupFinished(int resolve_result) { 82 void DNSResolveFunction::OnLookupFinished(int resolve_result) {
80 DictionaryValue* api_result = new DictionaryValue(); 83
81 api_result->SetInteger(kResultCodeKey, resolve_result); 84 scoped_ptr<ResolveCallbackResolveInfo> resolve_info(
85 new ResolveCallbackResolveInfo());
86 resolve_info->result_code = resolve_result;
82 if (resolve_result == net::OK) { 87 if (resolve_result == net::OK) {
83 const struct addrinfo* head = addresses_->head(); 88 const struct addrinfo* head = addresses_->head();
84 DCHECK(head); 89 DCHECK(head);
85 api_result->SetString(kAddressKey, net::NetAddressToString(head)); 90 resolve_info->address.reset(
91 new std::string(net::NetAddressToString(head)));
86 } 92 }
87 result_.reset(api_result); 93 result_.reset(Resolve::Result::Create(*resolve_info));
88 response_ = true; 94 response_ = true;
89 95
90 bool post_task_result = BrowserThread::PostTask( 96 bool post_task_result = BrowserThread::PostTask(
91 BrowserThread::UI, FROM_HERE, 97 BrowserThread::UI, FROM_HERE,
92 base::Bind(&DNSResolveFunction::RespondOnUIThread, this)); 98 base::Bind(&DNSResolveFunction::RespondOnUIThread, this));
93 DCHECK(post_task_result); 99 DCHECK(post_task_result);
94 100
95 Release(); // Added in WorkOnIOThread(). 101 Release(); // Added in WorkOnIOThread().
96 } 102 }
97 103
98 void DNSResolveFunction::RespondOnUIThread() { 104 void DNSResolveFunction::RespondOnUIThread() {
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
100 SendResponse(response_); 106 SendResponse(response_);
101 } 107 }
102 108
103 } // namespace extensions 109 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698