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

Side by Side Diff: chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc

Issue 1566047: First cut of Cloud Print Proxy implementation. The code is not enabled for no... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Final review changes Created 10 years, 8 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
6
7 #include <stack>
8 #include <vector>
9
10 #include "base/path_service.h"
11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_thread.h"
14 #include "chrome/browser/profile.h"
15 #include "chrome/browser/profile_manager.h"
16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/notification_type.h"
18 #include "chrome/common/pref_names.h"
19 #include "chrome/browser/pref_service.h"
20
21 CloudPrintProxyService::CloudPrintProxyService(Profile* profile) {
22 }
23
24 CloudPrintProxyService::~CloudPrintProxyService() {
25 Shutdown();
26 }
27
28 void CloudPrintProxyService::Initialize() {
29 PrefService* prefs = g_browser_process->local_state();
30 DCHECK(prefs);
31 prefs->RegisterStringPref(prefs::kCloudPrintProxyId, L"");
32 prefs->RegisterStringPref(prefs::kCloudPrintProxyName, L"");
33 prefs->RegisterStringPref(prefs::kCloudPrintAuthToken, L"");
34 }
35
36
37 void CloudPrintProxyService::EnableForUser(const std::string& auth_token) {
38 if (backend_.get())
39 return;
40
41 PrefService* prefs = g_browser_process->local_state();
42 DCHECK(prefs);
43 std::string proxy_id =
44 WideToUTF8(prefs->GetString(prefs::kCloudPrintProxyId));
45 if (proxy_id.empty()) {
46 // TODO(sanjeevr): Determine whether the proxy id should be server generated
47 proxy_id = cloud_print::GenerateProxyId();
48 prefs->SetString(prefs::kCloudPrintProxyId, UTF8ToWide(proxy_id));
49 }
50 std::string token_to_use = auth_token;
51 if (token_to_use.empty()) {
52 token_to_use = WideToUTF8(prefs->GetString(prefs::kCloudPrintAuthToken));
53 } else {
54 prefs->SetString(prefs::kCloudPrintAuthToken, UTF8ToWide(token_to_use));
55 }
56
57 backend_.reset(new CloudPrintProxyBackend(this));
58 backend_->Initialize(token_to_use, proxy_id);
59 }
60
61 void CloudPrintProxyService::DisableForUser() {
62 PrefService* prefs = g_browser_process->local_state();
63 DCHECK(prefs);
64 prefs->ClearPref(prefs::kCloudPrintAuthToken);
65 Shutdown();
66 }
67
68 void CloudPrintProxyService::HandlePrinterNotification(
69 const std::string& printer_id) {
70 if (backend_.get())
71 backend_->HandlePrinterNotification(printer_id);
72 }
73
74 void CloudPrintProxyService::Shutdown() {
75 if (backend_.get())
76 backend_->Shutdown();
77 backend_.reset();
78 }
79
80 // Notification methods from the backend. Called on UI thread.
81 void CloudPrintProxyService::OnPrinterListAvailable(
82 const cloud_print::PrinterList& printer_list) {
83 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
84 // Here we will trim the list to eliminate printers already registered.
85 // If there are any more printers left in the list after trimming, we will
86 // show the print selection UI. Any printers left in the list after the user
87 // selection process will then be registered.
88 backend_->RegisterPrinters(printer_list);
89 }
90
91 // Called when authentication is done. Called on UI thread.
92 // Note that sid can be empty. This is a temp function to steal the sid
93 // from the Bookmarks Sync code. When the common GAIA signin code is done,
94 // The CloudPrintProxyService will simply get a notification when authentication
95 // done with an lsid and a sid.
96 void CloudPrintProxyService::OnAuthenticated(const std::string& sid) {
97 FilePath user_data_dir;
98 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
99 ProfileManager* profile_manager = g_browser_process->profile_manager();
100 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir);
101 profile->GetCloudPrintProxyService()->EnableForUser(sid);
102 }
103
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698