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

Side by Side Diff: chrome/browser/policy/device_management_service.cc

Issue 5292003: Some cosmetic fixups to the device management service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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
« no previous file with comments | « no previous file | chrome/browser/profile.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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/policy/device_management_service.h" 5 #include "chrome/browser/policy/device_management_service.h"
6 6
7 #include "chrome/browser/browser_thread.h" 7 #include "chrome/browser/browser_thread.h"
8 #include "net/base/cookie_monster.h" 8 #include "net/base/cookie_monster.h"
9 #include "net/base/host_resolver.h" 9 #include "net/base/host_resolver.h"
10 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
11 #include "net/base/ssl_config_service_defaults.h" 11 #include "net/base/ssl_config_service_defaults.h"
12 #include "net/http/http_auth_handler_factory.h" 12 #include "net/http/http_auth_handler_factory.h"
13 #include "net/http/http_network_layer.h" 13 #include "net/http/http_network_layer.h"
14 #include "net/proxy/proxy_service.h" 14 #include "net/proxy/proxy_service.h"
15 #include "net/url_request/url_request_context.h" 15 #include "net/url_request/url_request_context.h"
16 #include "net/url_request/url_request_status.h" 16 #include "net/url_request/url_request_status.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/io_thread.h" 18 #include "chrome/browser/io_thread.h"
19 #include "chrome/browser/net/chrome_net_log.h" 19 #include "chrome/browser/net/chrome_net_log.h"
20 #include "chrome/browser/policy/device_management_backend_impl.h" 20 #include "chrome/browser/policy/device_management_backend_impl.h"
21 #include "chrome/common/net/url_request_context_getter.h" 21 #include "chrome/common/net/url_request_context_getter.h"
22 22
23 namespace policy { 23 namespace policy {
24 24
25 namespace { 25 namespace {
26 26
27 // Custom request context implementation that allows to override the user agent, 27 // Custom request context implementation that allows to override the user agent,
28 // amongst others. Wraps a baseline request context from which we reuse the 28 // amongst others. Wraps a baseline request context from which we reuse the
29 // networking components. 29 // networking components.
30 class DeviceManagementBackendRequestContext : public URLRequestContext { 30 class DeviceManagementRequestContext : public URLRequestContext {
31 public: 31 public:
32 explicit DeviceManagementBackendRequestContext( 32 explicit DeviceManagementRequestContext(URLRequestContext* base_context);
33 URLRequestContext* base_context); 33 virtual ~DeviceManagementRequestContext();
34 virtual ~DeviceManagementBackendRequestContext();
35 }; 34 };
36 35
37 DeviceManagementBackendRequestContext::DeviceManagementBackendRequestContext( 36 DeviceManagementRequestContext::DeviceManagementRequestContext(
38 URLRequestContext* base_context) { 37 URLRequestContext* base_context) {
39 // Share resolver, proxy service and ssl bits with the baseline context. This 38 // Share resolver, proxy service and ssl bits with the baseline context. This
40 // is important so we don't make redundant requests (e.g. when resolving proxy 39 // is important so we don't make redundant requests (e.g. when resolving proxy
41 // auto configuration). 40 // auto configuration).
42 net_log_ = base_context->net_log(); 41 net_log_ = base_context->net_log();
43 host_resolver_ = base_context->host_resolver(); 42 host_resolver_ = base_context->host_resolver();
44 proxy_service_ = base_context->proxy_service(); 43 proxy_service_ = base_context->proxy_service();
45 ssl_config_service_ = base_context->ssl_config_service(); 44 ssl_config_service_ = base_context->ssl_config_service();
46 45
47 // Share the http session. 46 // Share the http session.
48 http_transaction_factory_ = net::HttpNetworkLayer::CreateFactory( 47 http_transaction_factory_ = net::HttpNetworkLayer::CreateFactory(
49 base_context->http_transaction_factory()->GetSession()); 48 base_context->http_transaction_factory()->GetSession());
50 49
51 // No cookies, please. 50 // No cookies, please.
52 cookie_store_ = new net::CookieMonster(NULL, NULL); 51 cookie_store_ = new net::CookieMonster(NULL, NULL);
53 52
54 // Initialize these to sane values for our purposes. 53 // Initialize these to sane values for our purposes.
55 accept_language_ = "*"; 54 accept_language_ = "*";
56 accept_charset_ = "*"; 55 accept_charset_ = "*";
57 } 56 }
58 57
59 DeviceManagementBackendRequestContext 58 DeviceManagementRequestContext::~DeviceManagementRequestContext() {
60 ::~DeviceManagementBackendRequestContext() {
61 delete http_transaction_factory_; 59 delete http_transaction_factory_;
62 delete http_auth_handler_factory_; 60 delete http_auth_handler_factory_;
63 } 61 }
64 62
65 // Request context holder. 63 // Request context holder.
66 class DeviceManagementBackendRequestContextGetter 64 class DeviceManagementRequestContextGetter : public URLRequestContextGetter {
67 : public URLRequestContextGetter {
68 public: 65 public:
69 DeviceManagementBackendRequestContextGetter( 66 DeviceManagementRequestContextGetter(
70 URLRequestContextGetter* base_context_getter) 67 URLRequestContextGetter* base_context_getter)
71 : base_context_getter_(base_context_getter) {} 68 : base_context_getter_(base_context_getter) {}
72 69
73 // URLRequestContextGetter overrides. 70 // URLRequestContextGetter overrides.
74 virtual URLRequestContext* GetURLRequestContext(); 71 virtual URLRequestContext* GetURLRequestContext();
75 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; 72 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const;
76 73
77 private: 74 private:
78 scoped_refptr<URLRequestContext> context_; 75 scoped_refptr<URLRequestContext> context_;
79 scoped_refptr<URLRequestContextGetter> base_context_getter_; 76 scoped_refptr<URLRequestContextGetter> base_context_getter_;
80 }; 77 };
81 78
82 79
83 URLRequestContext* 80 URLRequestContext*
84 DeviceManagementBackendRequestContextGetter::GetURLRequestContext() { 81 DeviceManagementRequestContextGetter::GetURLRequestContext() {
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
86 if (!context_) { 83 if (!context_) {
87 context_ = new DeviceManagementBackendRequestContext( 84 context_ = new DeviceManagementRequestContext(
88 base_context_getter_->GetURLRequestContext()); 85 base_context_getter_->GetURLRequestContext());
89 } 86 }
90 87
91 return context_.get(); 88 return context_.get();
92 } 89 }
93 90
94 scoped_refptr<base::MessageLoopProxy> 91 scoped_refptr<base::MessageLoopProxy>
95 DeviceManagementBackendRequestContextGetter::GetIOMessageLoopProxy() const { 92 DeviceManagementRequestContextGetter::GetIOMessageLoopProxy() const {
96 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 93 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
97 } 94 }
98 95
99 } // namespace 96 } // namespace
100 97
101 DeviceManagementService::~DeviceManagementService() { 98 DeviceManagementService::~DeviceManagementService() {
102 // All running jobs should have been canceled by now. If not, there are 99 // All running jobs should have been canceled by now. If not, there are
103 // backend objects still around, which is an error. 100 // backend objects still around, which is an error.
104 DCHECK(pending_jobs_.empty()); 101 DCHECK(pending_jobs_.empty());
105 DCHECK(queued_jobs_.empty()); 102 DCHECK(queued_jobs_.empty());
106 } 103 }
107 104
108 DeviceManagementBackend* DeviceManagementService::CreateBackend() { 105 DeviceManagementBackend* DeviceManagementService::CreateBackend() {
109 return new DeviceManagementBackendImpl(this); 106 return new DeviceManagementBackendImpl(this);
110 } 107 }
111 108
112 void DeviceManagementService::Initialize( 109 void DeviceManagementService::Initialize(
113 URLRequestContextGetter* request_context_getter) { 110 URLRequestContextGetter* request_context_getter) {
114 DCHECK(!request_context_getter_); 111 DCHECK(!request_context_getter_);
115 request_context_getter_ = request_context_getter; 112 request_context_getter_ =
113 new DeviceManagementRequestContextGetter(request_context_getter);
116 while (!queued_jobs_.empty()) { 114 while (!queued_jobs_.empty()) {
117 StartJob(queued_jobs_.front()); 115 StartJob(queued_jobs_.front());
118 queued_jobs_.pop_front(); 116 queued_jobs_.pop_front();
119 } 117 }
120 } 118 }
121 119
122 void DeviceManagementService::Shutdown() { 120 void DeviceManagementService::Shutdown() {
123 for (JobFetcherMap::iterator job(pending_jobs_.begin()); 121 for (JobFetcherMap::iterator job(pending_jobs_.begin());
124 job != pending_jobs_.end(); 122 job != pending_jobs_.end();
125 ++job) { 123 ++job) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 DeviceManagementJob* job = entry->second; 174 DeviceManagementJob* job = entry->second;
177 job->HandleResponse(status, response_code, cookies, data); 175 job->HandleResponse(status, response_code, cookies, data);
178 pending_jobs_.erase(entry); 176 pending_jobs_.erase(entry);
179 } else { 177 } else {
180 NOTREACHED() << "Callback from foreign URL fetcher"; 178 NOTREACHED() << "Callback from foreign URL fetcher";
181 } 179 }
182 delete source; 180 delete source;
183 } 181 }
184 182
185 } // namespace policy 183 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698