| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   82       (!profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail).empty() || |   82       (!profile_->GetPrefs()->GetString(prefs::kCloudPrintEmail).empty() || | 
|   83        !profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled))) { |   83        !profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled))) { | 
|   84     // If the cloud print proxy is enabled, or the policy preventing it from |   84     // If the cloud print proxy is enabled, or the policy preventing it from | 
|   85     // being enabled is set, establish a channel with the service process and |   85     // being enabled is set, establish a channel with the service process and | 
|   86     // update the status. This will check the policy when the status is sent |   86     // update the status. This will check the policy when the status is sent | 
|   87     // back. |   87     // back. | 
|   88     RefreshStatusFromService(); |   88     RefreshStatusFromService(); | 
|   89   } |   89   } | 
|   90  |   90  | 
|   91   pref_change_registrar_.Init(profile_->GetPrefs()); |   91   pref_change_registrar_.Init(profile_->GetPrefs()); | 
|   92   pref_change_registrar_.Add(prefs::kCloudPrintProxyEnabled, this); |   92   pref_change_registrar_.Add( | 
 |   93       prefs::kCloudPrintProxyEnabled, | 
 |   94       base::Bind( | 
 |   95           base::IgnoreResult( | 
 |   96               &CloudPrintProxyService::ApplyCloudPrintConnectorPolicy), | 
 |   97           base::Unretained(this))); | 
|   93 } |   98 } | 
|   94  |   99  | 
|   95 void CloudPrintProxyService::RefreshStatusFromService() { |  100 void CloudPrintProxyService::RefreshStatusFromService() { | 
|   96   InvokeServiceTask( |  101   InvokeServiceTask( | 
|   97       base::Bind(&CloudPrintProxyService::RefreshCloudPrintProxyStatus, |  102       base::Bind(&CloudPrintProxyService::RefreshCloudPrintProxyStatus, | 
|   98                  weak_factory_.GetWeakPtr())); |  103                  weak_factory_.GetWeakPtr())); | 
|   99 } |  104 } | 
|  100  |  105  | 
|  101 bool CloudPrintProxyService::EnforceCloudPrintConnectorPolicyAndQuit() { |  106 bool CloudPrintProxyService::EnforceCloudPrintConnectorPolicyAndQuit() { | 
|  102   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  107   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  200     } |  205     } | 
|  201   } |  206   } | 
|  202   return true; |  207   return true; | 
|  203 } |  208 } | 
|  204  |  209  | 
|  205 void CloudPrintProxyService::OnCloudPrintSetupClosed() { |  210 void CloudPrintProxyService::OnCloudPrintSetupClosed() { | 
|  206   MessageLoop::current()->PostTask( |  211   MessageLoop::current()->PostTask( | 
|  207       FROM_HERE, base::Bind(&browser::EndKeepAlive)); |  212       FROM_HERE, base::Bind(&browser::EndKeepAlive)); | 
|  208 } |  213 } | 
|  209  |  214  | 
|  210 void CloudPrintProxyService::OnPreferenceChanged(PrefServiceBase* service, |  | 
|  211                                                  const std::string& pref_name) { |  | 
|  212   ApplyCloudPrintConnectorPolicy(); |  | 
|  213 } |  | 
|  214  |  | 
|  215 void CloudPrintProxyService::RefreshCloudPrintProxyStatus() { |  215 void CloudPrintProxyService::RefreshCloudPrintProxyStatus() { | 
|  216   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  216   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  217   ServiceProcessControl* process_control = GetServiceProcessControl(); |  217   ServiceProcessControl* process_control = GetServiceProcessControl(); | 
|  218   DCHECK(process_control->IsConnected()); |  218   DCHECK(process_control->IsConnected()); | 
|  219   ServiceProcessControl::CloudPrintProxyInfoHandler callback = |  219   ServiceProcessControl::CloudPrintProxyInfoHandler callback = | 
|  220        base::Bind(&CloudPrintProxyService::ProxyInfoCallback, |  220        base::Bind(&CloudPrintProxyService::ProxyInfoCallback, | 
|  221                   base::Unretained(this)); |  221                   base::Unretained(this)); | 
|  222   // GetCloudPrintProxyInfo takes ownership of callback. |  222   // GetCloudPrintProxyInfo takes ownership of callback. | 
|  223   process_control->GetCloudPrintProxyInfo(callback); |  223   process_control->GetCloudPrintProxyInfo(callback); | 
|  224 } |  224 } | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  266 } |  266 } | 
|  267  |  267  | 
|  268 bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { |  268 bool CloudPrintProxyService::InvokeServiceTask(const base::Closure& task) { | 
|  269   GetServiceProcessControl()->Launch(task, base::Closure()); |  269   GetServiceProcessControl()->Launch(task, base::Closure()); | 
|  270   return true; |  270   return true; | 
|  271 } |  271 } | 
|  272  |  272  | 
|  273 ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { |  273 ServiceProcessControl* CloudPrintProxyService::GetServiceProcessControl() { | 
|  274   return ServiceProcessControl::GetInstance(); |  274   return ServiceProcessControl::GetInstance(); | 
|  275 } |  275 } | 
| OLD | NEW |