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/service/cloud_print/cloud_print_proxy_backend.h" | 5 #include "chrome/service/cloud_print/cloud_print_proxy_backend.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/common/net/gaia/gaia_oauth_client.h" | 15 #include "chrome/common/net/gaia/gaia_oauth_client.h" |
16 #include "chrome/common/net/gaia/gaia_urls.h" | 16 #include "chrome/common/net/gaia/gaia_urls.h" |
17 #include "chrome/service/cloud_print/cloud_print_auth.h" | 17 #include "chrome/service/cloud_print/cloud_print_auth.h" |
18 #include "chrome/service/cloud_print/cloud_print_connector.h" | 18 #include "chrome/service/cloud_print/cloud_print_connector.h" |
19 #include "chrome/service/cloud_print/cloud_print_consts.h" | 19 #include "chrome/service/cloud_print/cloud_print_consts.h" |
20 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 20 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
21 #include "chrome/service/cloud_print/cloud_print_token_store.h" | 21 #include "chrome/service/cloud_print/cloud_print_token_store.h" |
22 #include "chrome/service/gaia/service_gaia_authenticator.h" | 22 #include "chrome/service/gaia/service_gaia_authenticator.h" |
23 #include "chrome/service/net/service_url_request_context.h" | 23 #include "chrome/service/net/service_url_request_context.h" |
24 #include "chrome/service/service_process.h" | 24 #include "chrome/service/service_process.h" |
25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
27 #include "jingle/notifier/base/notifier_options.h" | 27 #include "jingle/notifier/base/notifier_options.h" |
28 #include "jingle/notifier/listener/push_client.h" | 28 #include "jingle/notifier/listener/push_client.h" |
| 29 #include "jingle/notifier/listener/push_client_observer.h" |
29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
30 | 31 |
31 // The real guts of CloudPrintProxyBackend, to keep the public client API clean. | 32 // The real guts of CloudPrintProxyBackend, to keep the public client API clean. |
32 class CloudPrintProxyBackend::Core | 33 class CloudPrintProxyBackend::Core |
33 : public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>, | 34 : public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>, |
34 public CloudPrintAuth::Client, | 35 public CloudPrintAuth::Client, |
35 public CloudPrintConnector::Client, | 36 public CloudPrintConnector::Client, |
36 public notifier::PushClient::Observer { | 37 public notifier::PushClientObserver { |
37 public: | 38 public: |
38 // It is OK for print_server_url to be empty. In this case system should | 39 // It is OK for print_server_url to be empty. In this case system should |
39 // use system default (local) print server. | 40 // use system default (local) print server. |
40 Core(CloudPrintProxyBackend* backend, | 41 Core(CloudPrintProxyBackend* backend, |
41 const std::string& proxy_id, | 42 const std::string& proxy_id, |
42 const GURL& cloud_print_server_url, | 43 const GURL& cloud_print_server_url, |
43 const DictionaryValue* print_system_settings, | 44 const DictionaryValue* print_system_settings, |
44 const gaia::OAuthClientInfo& oauth_client_info, | 45 const gaia::OAuthClientInfo& oauth_client_info, |
45 bool enable_job_poll); | 46 bool enable_job_poll); |
46 | 47 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 virtual void OnAuthenticationComplete( | 80 virtual void OnAuthenticationComplete( |
80 const std::string& access_token, | 81 const std::string& access_token, |
81 const std::string& robot_oauth_refresh_token, | 82 const std::string& robot_oauth_refresh_token, |
82 const std::string& robot_email, | 83 const std::string& robot_email, |
83 const std::string& user_email) OVERRIDE; | 84 const std::string& user_email) OVERRIDE; |
84 virtual void OnInvalidCredentials() OVERRIDE; | 85 virtual void OnInvalidCredentials() OVERRIDE; |
85 | 86 |
86 // CloudPrintConnector::Client implementation. | 87 // CloudPrintConnector::Client implementation. |
87 virtual void OnAuthFailed() OVERRIDE; | 88 virtual void OnAuthFailed() OVERRIDE; |
88 | 89 |
89 // notifier::PushClient::Delegate implementation. | 90 // notifier::PushClientObserver implementation. |
90 virtual void OnNotificationStateChange( | 91 virtual void OnNotificationStateChange( |
91 bool notifications_enabled) OVERRIDE; | 92 bool notifications_enabled) OVERRIDE; |
92 virtual void OnIncomingNotification( | 93 virtual void OnIncomingNotification( |
93 const notifier::Notification& notification) OVERRIDE; | 94 const notifier::Notification& notification) OVERRIDE; |
94 | 95 |
95 private: | 96 private: |
96 friend class base::RefCountedThreadSafe<Core>; | 97 friend class base::RefCountedThreadSafe<Core>; |
97 | 98 |
98 virtual ~Core() {} | 99 virtual ~Core() {} |
99 | 100 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 384 |
384 void CloudPrintProxyBackend::Core::InitNotifications( | 385 void CloudPrintProxyBackend::Core::InitNotifications( |
385 const std::string& robot_email, | 386 const std::string& robot_email, |
386 const std::string& access_token) { | 387 const std::string& access_token) { |
387 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 388 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
388 | 389 |
389 notifier::NotifierOptions notifier_options; | 390 notifier::NotifierOptions notifier_options; |
390 notifier_options.request_context_getter = | 391 notifier_options.request_context_getter = |
391 g_service_process->GetServiceURLRequestContextGetter(); | 392 g_service_process->GetServiceURLRequestContextGetter(); |
392 notifier_options.auth_mechanism = "X-OAUTH2"; | 393 notifier_options.auth_mechanism = "X-OAUTH2"; |
393 push_client_.reset(new notifier::PushClient(notifier_options)); | 394 push_client_ = notifier::PushClient::CreateDefault(notifier_options); |
394 push_client_->AddObserver(this); | 395 push_client_->AddObserver(this); |
395 notifier::Subscription subscription; | 396 notifier::Subscription subscription; |
396 subscription.channel = kCloudPrintPushNotificationsSource; | 397 subscription.channel = kCloudPrintPushNotificationsSource; |
397 subscription.from = kCloudPrintPushNotificationsSource; | 398 subscription.from = kCloudPrintPushNotificationsSource; |
398 push_client_->UpdateSubscriptions( | 399 push_client_->UpdateSubscriptions( |
399 notifier::SubscriptionList(1, subscription)); | 400 notifier::SubscriptionList(1, subscription)); |
400 push_client_->UpdateCredentials(robot_email, access_token); | 401 push_client_->UpdateCredentials(robot_email, access_token); |
401 } | 402 } |
402 | 403 |
403 void CloudPrintProxyBackend::Core::DoShutdown() { | 404 void CloudPrintProxyBackend::Core::DoShutdown() { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 526 |
526 | 527 |
527 void CloudPrintProxyBackend::Core::OnIncomingNotification( | 528 void CloudPrintProxyBackend::Core::OnIncomingNotification( |
528 const notifier::Notification& notification) { | 529 const notifier::Notification& notification) { |
529 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 530 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
530 VLOG(1) << "CP_CONNECTOR: Incoming notification."; | 531 VLOG(1) << "CP_CONNECTOR: Incoming notification."; |
531 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource, | 532 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource, |
532 notification.channel.c_str())) | 533 notification.channel.c_str())) |
533 HandlePrinterNotification(notification.data); | 534 HandlePrinterNotification(notification.data); |
534 } | 535 } |
OLD | NEW |