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

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_linux.cc

Issue 2868433004: Linux native notifications: use image_path instead of image-path for spec 1.1 (Closed)
Patch Set: Created 3 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
« no previous file with comments | « no previous file | chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/notifications/notification_platform_bridge_linux.h" 5 #include "chrome/browser/notifications/notification_platform_bridge_linux.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <unordered_map> 10 #include <unordered_map>
11 #include <unordered_set> 11 #include <unordered_set>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/barrier_closure.h" 15 #include "base/barrier_closure.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/strings/nullable_string16.h" 18 #include "base/strings/nullable_string16.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_split.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
22 #include "base/task_scheduler/post_task.h" 23 #include "base/task_scheduler/post_task.h"
23 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
25 #include "chrome/browser/notifications/native_notification_display_service.h" 26 #include "chrome/browser/notifications/native_notification_display_service.h"
26 #include "chrome/browser/notifications/notification.h" 27 #include "chrome/browser/notifications/notification.h"
27 #include "chrome/browser/notifications/notification_display_service_factory.h" 28 #include "chrome/browser/notifications/notification_display_service_factory.h"
28 #include "chrome/browser/profiles/profile_manager.h" 29 #include "chrome/browser/profiles/profile_manager.h"
29 #include "chrome/browser/shell_integration_linux.h" 30 #include "chrome/browser/shell_integration_linux.h"
(...skipping 14 matching lines...) Expand all
44 45
45 // The values in this enumeration correspond to those of the 46 // The values in this enumeration correspond to those of the
46 // Linux.NotificationPlatformBridge.InitializationStatus histogram, so 47 // Linux.NotificationPlatformBridge.InitializationStatus histogram, so
47 // the ordering should not be changed. New error codes should be 48 // the ordering should not be changed. New error codes should be
48 // added at the end, before NUM_ITEMS. 49 // added at the end, before NUM_ITEMS.
49 enum class ConnectionInitializationStatusCode { 50 enum class ConnectionInitializationStatusCode {
50 SUCCESS = 0, 51 SUCCESS = 0,
51 NATIVE_NOTIFICATIONS_NOT_SUPPORTED = 1, 52 NATIVE_NOTIFICATIONS_NOT_SUPPORTED = 1,
52 MISSING_REQUIRED_CAPABILITIES = 2, 53 MISSING_REQUIRED_CAPABILITIES = 2,
53 COULD_NOT_CONNECT_TO_SIGNALS = 3, 54 COULD_NOT_CONNECT_TO_SIGNALS = 3,
55 INCOMPATIBLE_SPEC_VERSION = 4,
54 NUM_ITEMS 56 NUM_ITEMS
55 }; 57 };
56 58
57 gfx::Image DeepCopyImage(const gfx::Image& image) { 59 gfx::Image DeepCopyImage(const gfx::Image& image) {
58 if (image.IsEmpty()) 60 if (image.IsEmpty())
59 return gfx::Image(); 61 return gfx::Image();
60 std::unique_ptr<gfx::ImageSkia> image_skia(image.CopyImageSkia()); 62 std::unique_ptr<gfx::ImageSkia> image_skia(image.CopyImageSkia());
61 return gfx::Image(*image_skia); 63 return gfx::Image(*image_skia);
62 } 64 }
63 65
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 &get_capabilities_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT); 342 &get_capabilities_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
341 if (capabilities_response) { 343 if (capabilities_response) {
342 dbus::MessageReader reader(capabilities_response.get()); 344 dbus::MessageReader reader(capabilities_response.get());
343 std::vector<std::string> capabilities; 345 std::vector<std::string> capabilities;
344 reader.PopArrayOfStrings(&capabilities); 346 reader.PopArrayOfStrings(&capabilities);
345 for (const std::string& capability : capabilities) 347 for (const std::string& capability : capabilities)
346 capabilities_.insert(capability); 348 capabilities_.insert(capability);
347 } 349 }
348 RecordMetricsForCapabilities(); 350 RecordMetricsForCapabilities();
349 351
352 dbus::MethodCall get_server_information_call(kFreedesktopNotificationsName,
353 "GetServerInformation");
354 std::unique_ptr<dbus::Response> server_information_response =
355 notification_proxy_->CallMethodAndBlock(
356 &get_server_information_call,
357 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
358 if (server_information_response) {
359 dbus::MessageReader reader(server_information_response.get());
360 std::string spec_version;
361 reader.PopString(&spec_version); // name
362 reader.PopString(&spec_version); // vendor
363 reader.PopString(&spec_version); // version
364 reader.PopString(&spec_version); // spec_version
365 std::vector<std::string> spec_version_parts = base::SplitString(
366 spec_version, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
367 if (spec_version_parts.size() >= 2) {
368 base::StringToInt(spec_version_parts[0], &spec_version_major_);
369 base::StringToInt(spec_version_parts[1], &spec_version_minor_);
370 }
371 }
372 // The minimum supported spec version is 1.1, because this was the
373 // version that added image hints.
374 if (spec_version_major_ < 1 ||
375 (spec_version_major_ == 1 && spec_version_minor_ < 1)) {
376 OnConnectionInitializationFinishedOnTaskRunner(
377 ConnectionInitializationStatusCode::INCOMPATIBLE_SPEC_VERSION);
378 return;
379 }
380
350 connected_signals_barrier_ = base::BarrierClosure( 381 connected_signals_barrier_ = base::BarrierClosure(
351 2, base::Bind(&NotificationPlatformBridgeLinuxImpl:: 382 2, base::Bind(&NotificationPlatformBridgeLinuxImpl::
352 OnConnectionInitializationFinishedOnTaskRunner, 383 OnConnectionInitializationFinishedOnTaskRunner,
353 this, ConnectionInitializationStatusCode::SUCCESS)); 384 this, ConnectionInitializationStatusCode::SUCCESS));
354 notification_proxy_->ConnectToSignal( 385 notification_proxy_->ConnectToSignal(
355 kFreedesktopNotificationsName, "ActionInvoked", 386 kFreedesktopNotificationsName, "ActionInvoked",
356 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnActionInvoked, this), 387 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnActionInvoked, this),
357 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnSignalConnected, 388 base::Bind(&NotificationPlatformBridgeLinuxImpl::OnSignalConnected,
358 this)); 389 this));
359 notification_proxy_->ConnectToSignal( 390 notification_proxy_->ConnectToSignal(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 hints_writer.OpenDictEntry(&desktop_entry_writer); 496 hints_writer.OpenDictEntry(&desktop_entry_writer);
466 desktop_entry_writer.AppendString("desktop-entry"); 497 desktop_entry_writer.AppendString("desktop-entry");
467 desktop_entry_writer.AppendVariantOfString(desktop_file.value()); 498 desktop_entry_writer.AppendVariantOfString(desktop_file.value());
468 hints_writer.CloseContainer(&desktop_entry_writer); 499 hints_writer.CloseContainer(&desktop_entry_writer);
469 500
470 std::unique_ptr<ResourceFile> icon_file = 501 std::unique_ptr<ResourceFile> icon_file =
471 WriteDataToTmpFile(notification->icon().As1xPNGBytes()); 502 WriteDataToTmpFile(notification->icon().As1xPNGBytes());
472 if (icon_file) { 503 if (icon_file) {
473 dbus::MessageWriter image_path_writer(nullptr); 504 dbus::MessageWriter image_path_writer(nullptr);
474 hints_writer.OpenDictEntry(&image_path_writer); 505 hints_writer.OpenDictEntry(&image_path_writer);
475 image_path_writer.AppendString("image-path"); 506 if (spec_version_major_ == 1 && spec_version_minor_ == 1) {
507 image_path_writer.AppendString("image_path");
Lei Zhang 2017/05/08 21:51:19 image_path_writer.AppendString(some_eval ? "image_
Tom (Use chromium acct) 2017/05/08 22:46:07 Done.
508 } else {
509 image_path_writer.AppendString("image-path");
510 }
476 image_path_writer.AppendVariantOfString(icon_file->file_path().value()); 511 image_path_writer.AppendVariantOfString(icon_file->file_path().value());
477 hints_writer.CloseContainer(&image_path_writer); 512 hints_writer.CloseContainer(&image_path_writer);
478 data->resource_files.push_back(std::move(icon_file)); 513 data->resource_files.push_back(std::move(icon_file));
479 } 514 }
480 515
481 writer.CloseContainer(&hints_writer); 516 writer.CloseContainer(&hints_writer);
482 517
483 const int32_t kExpireTimeoutDefault = -1; 518 const int32_t kExpireTimeoutDefault = -1;
484 writer.AppendInt32(kExpireTimeoutDefault); 519 writer.AppendInt32(kExpireTimeoutDefault);
485 520
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 728
694 ////////////////////////////////////////////////////////////////////////////// 729 //////////////////////////////////////////////////////////////////////////////
695 // Members used only on the task runner thread. 730 // Members used only on the task runner thread.
696 731
697 scoped_refptr<dbus::Bus> bus_; 732 scoped_refptr<dbus::Bus> bus_;
698 733
699 dbus::ObjectProxy* notification_proxy_ = nullptr; 734 dbus::ObjectProxy* notification_proxy_ = nullptr;
700 735
701 std::unordered_set<std::string> capabilities_; 736 std::unordered_set<std::string> capabilities_;
702 737
738 int spec_version_major_ = -1;
Lei Zhang 2017/05/08 21:51:19 Can we make these local variables to InitOnTaskRun
Tom (Use chromium acct) 2017/05/08 22:46:07 Even better I think is a std::pair<int, int> (done
Lei Zhang 2017/05/08 22:54:25 FWIW, there's also base::Version. I'm not going to
739 int spec_version_minor_ = -1;
740
703 base::Closure connected_signals_barrier_; 741 base::Closure connected_signals_barrier_;
704 742
705 // A std::set<std::unique_ptr<T>> doesn't work well because 743 // A std::set<std::unique_ptr<T>> doesn't work well because
706 // eg. std::set::erase(T) would require a std::unique_ptr<T> 744 // eg. std::set::erase(T) would require a std::unique_ptr<T>
707 // argument, so the data would get double-destructed. 745 // argument, so the data would get double-destructed.
708 template <typename T> 746 template <typename T>
709 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>; 747 using UnorderedUniqueSet = std::unordered_map<T*, std::unique_ptr<T>>;
710 748
711 UnorderedUniqueSet<NotificationData> notifications_; 749 UnorderedUniqueSet<NotificationData> notifications_;
712 750
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 } 786 }
749 787
750 void NotificationPlatformBridgeLinux::SetReadyCallback( 788 void NotificationPlatformBridgeLinux::SetReadyCallback(
751 NotificationBridgeReadyCallback callback) { 789 NotificationBridgeReadyCallback callback) {
752 impl_->SetReadyCallback(std::move(callback)); 790 impl_->SetReadyCallback(std::move(callback));
753 } 791 }
754 792
755 void NotificationPlatformBridgeLinux::CleanUp() { 793 void NotificationPlatformBridgeLinux::CleanUp() {
756 impl_->CleanUp(); 794 impl_->CleanUp();
757 } 795 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/notifications/notification_platform_bridge_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698