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

Side by Side Diff: chrome/browser/chromeos/dbus/printer_service_provider.cc

Issue 1130933005: Remove code for showing cloud print page on plugging-in a printer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update histograms Created 5 years, 7 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
OLDNEW
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/chromeos/dbus/printer_service_provider.h" 5 #include "chrome/browser/chromeos/dbus/printer_service_provider.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
11 #include "ash/session/session_state_delegate.h"
12 #include "ash/shell.h"
13 #include "ash/wm/window_util.h"
14 #include "base/bind.h" 11 #include "base/bind.h"
15 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
16 #include "base/command_line.h" 13 #include "base/command_line.h"
17 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
18 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
19 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
22 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
23 #include "base/sys_info.h"
24 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/chromeos/profiles/profile_helper.h" 21 #include "chrome/browser/chromeos/profiles/profile_helper.h"
26 #include "chrome/browser/notifications/notification.h" 22 #include "chrome/browser/notifications/notification.h"
27 #include "chrome/browser/notifications/notification_delegate.h" 23 #include "chrome/browser/notifications/notification_delegate.h"
28 #include "chrome/browser/notifications/notification_ui_manager.h" 24 #include "chrome/browser/notifications/notification_ui_manager.h"
29 #include "chrome/browser/profiles/profile_manager.h"
30 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_tabstrip.h"
32 #include "chrome/browser/ui/browser_window.h"
33 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
34 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
35 #include "chrome/browser/ui/tabs/tab_strip_model.h"
36 #include "chrome/common/chrome_version_info.h"
37 #include "chrome/common/extensions/api/webstore_widget_private.h" 25 #include "chrome/common/extensions/api/webstore_widget_private.h"
38 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
39 #include "chrome/grit/generated_resources.h" 27 #include "chrome/grit/generated_resources.h"
40 #include "chromeos/chromeos_switches.h" 28 #include "chromeos/chromeos_switches.h"
41 #include "components/user_manager/user.h" 29 #include "components/user_manager/user.h"
42 #include "components/user_manager/user_manager.h" 30 #include "components/user_manager/user_manager.h"
43 #include "content/public/browser/browser_thread.h"
44 #include "content/public/browser/web_contents.h"
45 #include "dbus/bus.h" 31 #include "dbus/bus.h"
46 #include "dbus/exported_object.h" 32 #include "dbus/exported_object.h"
47 #include "dbus/message.h" 33 #include "dbus/message.h"
48 #include "device/usb/usb_ids.h" 34 #include "device/usb/usb_ids.h"
49 #include "extensions/browser/event_router.h" 35 #include "extensions/browser/event_router.h"
50 #include "extensions/browser/extension_registry.h" 36 #include "extensions/browser/extension_registry.h"
51 #include "extensions/common/extension.h" 37 #include "extensions/common/extension.h"
52 #include "extensions/common/extension_set.h" 38 #include "extensions/common/extension_set.h"
53 #include "extensions/common/permissions/api_permission.h" 39 #include "extensions/common/permissions/api_permission.h"
54 #include "extensions/common/permissions/permissions_data.h" 40 #include "extensions/common/permissions/permissions_data.h"
55 #include "extensions/common/permissions/usb_device_permission.h" 41 #include "extensions/common/permissions/usb_device_permission.h"
56 #include "grit/theme_resources.h" 42 #include "grit/theme_resources.h"
57 #include "net/base/escape.h"
58 #include "third_party/cros_system_api/dbus/service_constants.h" 43 #include "third_party/cros_system_api/dbus/service_constants.h"
59 #include "ui/aura/window.h"
60 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
61 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
62 46
63 namespace webstore_widget_private_api = 47 namespace webstore_widget_private_api =
64 extensions::api::webstore_widget_private; 48 extensions::api::webstore_widget_private;
65 49
66 namespace { 50 namespace {
67 51
68 const char kPrinterAdded[] = "PrinterAdded"; 52 const char kPrinterAdded[] = "PrinterAdded";
69 53
70 const char kPrinterProviderFoundNotificationID[] = 54 const char kPrinterProviderFoundNotificationID[] =
71 "chrome://settings/printer/printer_app_found"; 55 "chrome://settings/printer/printer_app_found";
72 56
73 const char kNoPrinterProviderNotificationID[] = 57 const char kNoPrinterProviderNotificationID[] =
74 "chrome://settings/printer/no_printer_app"; 58 "chrome://settings/printer/no_printer_app";
75 59
76 enum PrinterServiceEvent { 60 enum PrinterServiceEvent {
77 PRINTER_ADDED, 61 PRINTER_ADDED,
78 PAGE_DISPLAYED, 62 DEPRECATED_PAGE_DISPLAYED,
63 NOTIFICATION_SHOWN_PRINTER_SUPPORTED,
64 NOTIFICATION_SHOWN_PRINTER_NOT_SUPPORTED,
65 WEBSTORE_WIDGET_APP_LAUNCHED,
79 PRINTER_SERVICE_EVENT_MAX, 66 PRINTER_SERVICE_EVENT_MAX,
80 }; 67 };
81 68
82 // TODO(vitalybuka): update URL with more relevant information.
83 const char kCloudPrintLearnUrl[] =
84 "https://www.google.com/landing/cloudprint/index.html";
85
86 void ActivateContents(Browser* browser, content::WebContents* contents) {
87 browser->tab_strip_model()->ActivateTabAt(
88 browser->tab_strip_model()->GetIndexOfWebContents(contents), false);
89 }
90
91 Browser* ActivateAndGetBrowserForUrl(GURL url) {
92 for (TabContentsIterator it; !it.done(); it.Next()) {
93 if (it->GetLastCommittedURL() == url) {
94 ActivateContents(it.browser(), *it);
95 return it.browser();
96 }
97 }
98 return nullptr;
99 }
100
101 bool HexStringToUInt16(const std::string& input, uint16* output) { 69 bool HexStringToUInt16(const std::string& input, uint16* output) {
102 uint32 output_uint = 0; 70 uint32 output_uint = 0;
103 if (!base::HexStringToUInt(input, &output_uint) || 71 if (!base::HexStringToUInt(input, &output_uint) ||
104 output_uint > std::numeric_limits<uint16>::max()) 72 output_uint > std::numeric_limits<uint16>::max())
105 return false; 73 return false;
106 *output = static_cast<uint16>(output_uint); 74 *output = static_cast<uint16>(output_uint);
107 return true; 75 return true;
108 } 76 }
109 77
110 void FindOrOpenCloudPrintPage(const std::string& /* vendor */,
111 const std::string& /* product */) {
112 UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent", PRINTER_ADDED,
113 PRINTER_SERVICE_EVENT_MAX);
114 if (!ash::Shell::GetInstance()->session_state_delegate()->
115 IsActiveUserSessionStarted() ||
116 ash::Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) {
117 return;
118 }
119
120 Profile* profile = ProfileManager::GetLastUsedProfile();
121 if (!profile)
122 return;
123
124 GURL url(kCloudPrintLearnUrl);
125
126 if (!ActivateAndGetBrowserForUrl(url)) {
127 chrome::ScopedTabbedBrowserDisplayer displayer(
128 profile, chrome::HOST_DESKTOP_TYPE_ASH);
129 UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent",
130 PAGE_DISPLAYED, PRINTER_SERVICE_EVENT_MAX);
131 chrome::AddSelectedTabWithURL(displayer.browser(), url,
132 ui::PAGE_TRANSITION_LINK);
133 }
134 }
135
136 base::string16 GetNotificationTitle(uint16 vendor_id, uint16 product_id) { 78 base::string16 GetNotificationTitle(uint16 vendor_id, uint16 product_id) {
137 const char* vendor_name = device::UsbIds::GetVendorName(vendor_id); 79 const char* vendor_name = device::UsbIds::GetVendorName(vendor_id);
138 if (vendor_name) { 80 if (vendor_name) {
139 return l10n_util::GetStringFUTF16(IDS_PRINTER_DETECTED_NOTIFICATION_TITLE, 81 return l10n_util::GetStringFUTF16(IDS_PRINTER_DETECTED_NOTIFICATION_TITLE,
140 base::UTF8ToUTF16(vendor_name)); 82 base::UTF8ToUTF16(vendor_name));
141 } else { 83 } else {
142 return l10n_util::GetStringUTF16( 84 return l10n_util::GetStringUTF16(
143 IDS_PRINTER_DETECTED_NOTIFICATION_TITLE_UNKNOWN_VENDOR); 85 IDS_PRINTER_DETECTED_NOTIFICATION_TITLE_UNKNOWN_VENDOR);
144 } 86 }
145 } 87 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 product_id_(product_id), 158 product_id_(product_id),
217 product_id_str_(product_id_str) {} 159 product_id_str_(product_id_str) {}
218 160
219 std::string id() const override { 161 std::string id() const override {
220 return "system.printer.no_printer_provider_found/" + 162 return "system.printer.no_printer_provider_found/" +
221 GetNotificationTag(vendor_id_str_, product_id_str_); 163 GetNotificationTag(vendor_id_str_, product_id_str_);
222 } 164 }
223 bool HasClickedListener() override { return true; } 165 bool HasClickedListener() override { return true; }
224 166
225 void Click() override { 167 void Click() override {
168 UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent",
169 WEBSTORE_WIDGET_APP_LAUNCHED,
170 PRINTER_SERVICE_EVENT_MAX);
226 webstore_widget_private_api::Options options; 171 webstore_widget_private_api::Options options;
227 options.type = webstore_widget_private_api::TYPE_PRINTER_PROVIDER; 172 options.type = webstore_widget_private_api::TYPE_PRINTER_PROVIDER;
228 options.usb_id.reset(new webstore_widget_private_api::UsbId()); 173 options.usb_id.reset(new webstore_widget_private_api::UsbId());
229 options.usb_id->vendor_id = vendor_id_; 174 options.usb_id->vendor_id = vendor_id_;
230 options.usb_id->product_id = product_id_; 175 options.usb_id->product_id = product_id_;
231 176
232 extensions::EventRouter* event_router = 177 extensions::EventRouter* event_router =
233 extensions::EventRouter::Get(browser_context_); 178 extensions::EventRouter::Get(browser_context_);
234 scoped_ptr<extensions::Event> event(new extensions::Event( 179 scoped_ptr<extensions::Event> event(new extensions::Event(
235 webstore_widget_private_api::OnShowWidget::kEventName, 180 webstore_widget_private_api::OnShowWidget::kEventName,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 return; 220 return;
276 221
277 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); 222 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user);
278 if (!profile) 223 if (!profile)
279 return; 224 return;
280 225
281 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 226 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
282 scoped_ptr<Notification> notification; 227 scoped_ptr<Notification> notification;
283 228
284 if (HasAppThatSupportsPrinter(profile, vendor_id, product_id)) { 229 if (HasAppThatSupportsPrinter(profile, vendor_id, product_id)) {
230 UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent",
231 NOTIFICATION_SHOWN_PRINTER_SUPPORTED,
232 PRINTER_SERVICE_EVENT_MAX);
285 notification.reset(new Notification( 233 notification.reset(new Notification(
286 message_center::NOTIFICATION_TYPE_SIMPLE, 234 message_center::NOTIFICATION_TYPE_SIMPLE,
287 GURL(kPrinterProviderFoundNotificationID), 235 GURL(kPrinterProviderFoundNotificationID),
288 GetNotificationTitle(vendor_id, product_id), 236 GetNotificationTitle(vendor_id, product_id),
289 l10n_util::GetStringUTF16( 237 l10n_util::GetStringUTF16(
290 IDS_PRINTER_DETECTED_NOTIFICATION_PRINT_APP_FOUND_BODY), 238 IDS_PRINTER_DETECTED_NOTIFICATION_PRINT_APP_FOUND_BODY),
291 bundle.GetImageNamed(IDR_PRINTER_NOTIFICATION), 239 bundle.GetImageNamed(IDR_PRINTER_NOTIFICATION),
292 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 240 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
293 kPrinterProviderFoundNotificationID), 241 kPrinterProviderFoundNotificationID),
294 base::string16(), GetNotificationTag(vendor_id_str, product_id_str), 242 base::string16(), GetNotificationTag(vendor_id_str, product_id_str),
295 message_center::RichNotificationData(), 243 message_center::RichNotificationData(),
296 new PrinterProviderExistsNotificationDelegate(vendor_id_str, 244 new PrinterProviderExistsNotificationDelegate(vendor_id_str,
297 product_id_str))); 245 product_id_str)));
298 } else { 246 } else {
247 UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent",
248 NOTIFICATION_SHOWN_PRINTER_NOT_SUPPORTED,
249 PRINTER_SERVICE_EVENT_MAX);
299 message_center::RichNotificationData options; 250 message_center::RichNotificationData options;
300 options.clickable = true; 251 options.clickable = true;
301 notification.reset(new Notification( 252 notification.reset(new Notification(
302 message_center::NOTIFICATION_TYPE_SIMPLE, 253 message_center::NOTIFICATION_TYPE_SIMPLE,
303 GURL(kNoPrinterProviderNotificationID), 254 GURL(kNoPrinterProviderNotificationID),
304 GetNotificationTitle(vendor_id, product_id), 255 GetNotificationTitle(vendor_id, product_id),
305 l10n_util::GetStringUTF16( 256 l10n_util::GetStringUTF16(
306 IDS_PRINTER_DETECTED_NOTIFICATION_NO_PRINT_APP_BODY), 257 IDS_PRINTER_DETECTED_NOTIFICATION_NO_PRINT_APP_BODY),
307 bundle.GetImageNamed(IDR_PRINTER_NOTIFICATION), 258 bundle.GetImageNamed(IDR_PRINTER_NOTIFICATION),
308 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 259 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 const std::string& interface_name, 302 const std::string& interface_name,
352 const std::string& method_name, 303 const std::string& method_name,
353 bool success) { 304 bool success) {
354 if (!success) { 305 if (!success) {
355 LOG(ERROR) << "Failed to export " << interface_name << "." 306 LOG(ERROR) << "Failed to export " << interface_name << "."
356 << method_name; 307 << method_name;
357 } 308 }
358 DVLOG(1) << "Method exported: " << interface_name << "." << method_name; 309 DVLOG(1) << "Method exported: " << interface_name << "." << method_name;
359 } 310 }
360 311
361 void PrinterServiceProvider::ShowCloudPrintHelp(const std::string& vendor,
362 const std::string& product) {
363 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
364 base::Bind(&FindOrOpenCloudPrintPage, vendor,
365 product));
366 }
367
368 void PrinterServiceProvider::PrinterAdded( 312 void PrinterServiceProvider::PrinterAdded(
369 dbus::MethodCall* method_call, 313 dbus::MethodCall* method_call,
370 dbus::ExportedObject::ResponseSender response_sender) { 314 dbus::ExportedObject::ResponseSender response_sender) {
371 DVLOG(1) << "PrinterAdded " << method_call->ToString(); 315 DVLOG(1) << "PrinterAdded " << method_call->ToString();
372 dbus::MessageReader reader(method_call); 316 dbus::MessageReader reader(method_call);
373 317
374 std::string vendor_id; 318 std::string vendor_id;
375 reader.PopString(&vendor_id); 319 reader.PopString(&vendor_id);
376 StringToUpperASCII(&vendor_id); 320 StringToUpperASCII(&vendor_id);
377 321
378 std::string product_id; 322 std::string product_id;
379 reader.PopString(&product_id); 323 reader.PopString(&product_id);
380 StringToUpperASCII(&product_id); 324 StringToUpperASCII(&product_id);
381 325
382 // Send an empty response. 326 // Send an empty response.
383 response_sender.Run(dbus::Response::FromMethodCall(method_call)); 327 response_sender.Run(dbus::Response::FromMethodCall(method_call));
384 328
385 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 329 UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent", PRINTER_ADDED,
330 PRINTER_SERVICE_EVENT_MAX);
331
332 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
386 switches::kEnablePrinterAppSearch)) { 333 switches::kEnablePrinterAppSearch)) {
387 ShowPrinterPluggedNotification(
388 notification_ui_manager_ ? notification_ui_manager_
389 : g_browser_process->notification_ui_manager(),
390 vendor_id, product_id);
391 return; 334 return;
392 } 335 }
393 336
394 // Disable showing Cloudprint help on canary and dev channel, as these have 337 ShowPrinterPluggedNotification(
395 // support for printerProvider API. 338 notification_ui_manager_ ? notification_ui_manager_
396 // TODO(tbarzic): Remove this and offer the user to search for an extension 339 : g_browser_process->notification_ui_manager(),
397 // that can act as a print driver (using printerProvider API) for USB printers 340 vendor_id, product_id);
398 // detected by this service. http://crbug.com/439448
399 if (base::SysInfo::IsRunningOnChromeOS() &&
400 chrome::VersionInfo::GetChannel() <= chrome::VersionInfo::CHANNEL_DEV)
401 return;
402
403 ShowCloudPrintHelp(vendor_id, product_id);
404 } 341 }
405 342
406 } // namespace chromeos 343 } // namespace chromeos
407 344
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698