| OLD | NEW |
| 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/printing/cloud_print/cloud_print_proxy_service.h" | 5 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
| 6 | 6 |
| 7 #include <stack> | 7 #include <stack> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/common/cloud_print/cloud_print_proxy_info.h" | 28 #include "chrome/common/cloud_print/cloud_print_proxy_info.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/service_messages.h" | 30 #include "chrome/common/service_messages.h" |
| 31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "printing/backend/print_backend.h" | 32 #include "printing/backend/print_backend.h" |
| 33 | 33 |
| 34 using content::BrowserThread; | 34 using content::BrowserThread; |
| 35 | 35 |
| 36 CloudPrintProxyService::CloudPrintProxyService(Profile* profile) | 36 CloudPrintProxyService::CloudPrintProxyService(Profile* profile) |
| 37 : profile_(profile), | 37 : profile_(profile), |
| 38 enforcing_connector_policy_(false), | |
| 39 weak_factory_(this) { | 38 weak_factory_(this) { |
| 40 } | 39 } |
| 41 | 40 |
| 42 CloudPrintProxyService::~CloudPrintProxyService() { | 41 CloudPrintProxyService::~CloudPrintProxyService() { |
| 43 } | 42 } |
| 44 | 43 |
| 45 void CloudPrintProxyService::Initialize() { | 44 void CloudPrintProxyService::Initialize() { |
| 46 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 45 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 47 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", | 46 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", |
| 48 ServiceProcessControl::SERVICE_EVENT_INITIALIZE, | 47 ServiceProcessControl::SERVICE_EVENT_INITIALIZE, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 70 base::Unretained(this))); | 69 base::Unretained(this))); |
| 71 } | 70 } |
| 72 | 71 |
| 73 void CloudPrintProxyService::RefreshStatusFromService() { | 72 void CloudPrintProxyService::RefreshStatusFromService() { |
| 74 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 73 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 75 InvokeServiceTask( | 74 InvokeServiceTask( |
| 76 base::Bind(&CloudPrintProxyService::RefreshCloudPrintProxyStatus, | 75 base::Bind(&CloudPrintProxyService::RefreshCloudPrintProxyStatus, |
| 77 weak_factory_.GetWeakPtr())); | 76 weak_factory_.GetWeakPtr())); |
| 78 } | 77 } |
| 79 | 78 |
| 80 bool CloudPrintProxyService::EnforceCloudPrintConnectorPolicyAndQuit() { | |
| 81 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 82 enforcing_connector_policy_ = true; | |
| 83 if (ApplyCloudPrintConnectorPolicy()) | |
| 84 return true; | |
| 85 return false; | |
| 86 } | |
| 87 | |
| 88 void CloudPrintProxyService::EnableForUserWithRobot( | 79 void CloudPrintProxyService::EnableForUserWithRobot( |
| 89 const std::string& robot_auth_code, | 80 const std::string& robot_auth_code, |
| 90 const std::string& robot_email, | 81 const std::string& robot_email, |
| 91 const std::string& user_email, | 82 const std::string& user_email, |
| 92 const base::DictionaryValue& user_preferences) { | 83 const base::DictionaryValue& user_preferences) { |
| 93 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 84 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 94 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", | 85 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", |
| 95 ServiceProcessControl::SERVICE_EVENT_ENABLE, | 86 ServiceProcessControl::SERVICE_EVENT_ENABLE, |
| 96 ServiceProcessControl::SERVICE_EVENT_MAX); | 87 ServiceProcessControl::SERVICE_EVENT_MAX); |
| 97 if (profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { | 88 if (profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 117 if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { | 108 if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { |
| 118 std::string email = | 109 std::string email = |
| 119 profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail); | 110 profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail); |
| 120 if (!email.empty()) { | 111 if (!email.empty()) { |
| 121 UMA_HISTOGRAM_ENUMERATION( | 112 UMA_HISTOGRAM_ENUMERATION( |
| 122 "CloudPrint.ServiceEvents", | 113 "CloudPrint.ServiceEvents", |
| 123 ServiceProcessControl::SERVICE_EVENT_DISABLE_BY_POLICY, | 114 ServiceProcessControl::SERVICE_EVENT_DISABLE_BY_POLICY, |
| 124 ServiceProcessControl::SERVICE_EVENT_MAX); | 115 ServiceProcessControl::SERVICE_EVENT_MAX); |
| 125 DisableForUser(); | 116 DisableForUser(); |
| 126 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); | 117 profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, std::string()); |
| 127 if (enforcing_connector_policy_) { | |
| 128 base::MessageLoop::current()->PostTask( | |
| 129 FROM_HERE, | |
| 130 base::Bind(&CloudPrintProxyService::RefreshCloudPrintProxyStatus, | |
| 131 weak_factory_.GetWeakPtr())); | |
| 132 } | |
| 133 return false; | 118 return false; |
| 134 } else if (enforcing_connector_policy_) { | |
| 135 base::MessageLoop::current()->PostTask(FROM_HERE, | |
| 136 base::MessageLoop::QuitClosure()); | |
| 137 } | 119 } |
| 138 } | 120 } |
| 139 return true; | 121 return true; |
| 140 } | 122 } |
| 141 | 123 |
| 142 void CloudPrintProxyService::GetPrinters(const PrintersCallback& callback) { | 124 void CloudPrintProxyService::GetPrinters(const PrintersCallback& callback) { |
| 143 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 125 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 144 if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) | 126 if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) |
| 145 return; | 127 return; |
| 146 | 128 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 203 } |
| 222 | 204 |
| 223 bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { | 205 bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { |
| 224 GetServiceProcessControl()->Launch(task, base::Closure()); | 206 GetServiceProcessControl()->Launch(task, base::Closure()); |
| 225 return true; | 207 return true; |
| 226 } | 208 } |
| 227 | 209 |
| 228 ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { | 210 ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { |
| 229 return ServiceProcessControl::GetInstance(); | 211 return ServiceProcessControl::GetInstance(); |
| 230 } | 212 } |
| OLD | NEW |