| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/policy/consumer_management_notifier.h" | 5 #include "chrome/browser/chromeos/policy/consumer_management_notifier.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/notifications/notification.h" | 14 #include "chrome/browser/notifications/notification.h" |
| 12 #include "chrome/browser/notifications/notification_delegate.h" | 15 #include "chrome/browser/notifications/notification_delegate.h" |
| 13 #include "chrome/browser/notifications/notification_ui_manager.h" | 16 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 14 #include "chrome/browser/ui/browser_navigator.h" | 17 #include "chrome/browser/ui/browser_navigator.h" |
| 15 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 16 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 17 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 18 #include "third_party/WebKit/public/web/WebTextDirection.h" | 21 #include "third_party/WebKit/public/web/WebTextDirection.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/page_transition_types.h" | 23 #include "ui/base/page_transition_types.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/base/window_open_disposition.h" | 25 #include "ui/base/window_open_disposition.h" |
| 26 #include "ui/message_center/notification_types.h" |
| 23 #include "ui/message_center/notifier_settings.h" | 27 #include "ui/message_center/notifier_settings.h" |
| 24 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 25 | 29 |
| 26 namespace { | 30 namespace { |
| 27 | 31 |
| 28 // Desktop notification constants. | 32 // Desktop notification constants. |
| 29 const char kEnrollmentNotificationId[] = "consumer_management.enroll"; | 33 const char kEnrollmentNotificationId[] = "consumer_management.enroll"; |
| 30 const char kEnrollmentNotificationUrl[] = "chrome://consumer-management/enroll"; | 34 const char kEnrollmentNotificationUrl[] = "chrome://consumer-management/enroll"; |
| 31 | 35 |
| 32 // The path to the consumer management enrollment/unenrollment confirmation | 36 // The path to the consumer management enrollment/unenrollment confirmation |
| 33 // overlay, relative to the settings page URL. | 37 // overlay, relative to the settings page URL. |
| 34 const char kConsumerManagementOverlay[] = "consumer-management-overlay"; | 38 const char kConsumerManagementOverlay[] = "consumer-management-overlay"; |
| 35 | 39 |
| 36 class DesktopNotificationDelegate : public NotificationDelegate { | 40 class DesktopNotificationDelegate : public NotificationDelegate { |
| 37 public: | 41 public: |
| 38 // |button_click_callback| is called when the button in the notification is | 42 // |button_click_callback| is called when the button in the notification is |
| 39 // clicked. | 43 // clicked. |
| 40 DesktopNotificationDelegate(const std::string& id, | 44 DesktopNotificationDelegate(const std::string& id, |
| 41 const base::Closure& button_click_callback); | 45 const base::Closure& button_click_callback); |
| 42 | 46 |
| 43 // NotificationDelegate: | 47 // NotificationDelegate: |
| 44 std::string id() const override; | 48 std::string id() const override; |
| 45 void ButtonClick(int button_index) override; | 49 void ButtonClick(int button_index) override; |
| 46 | 50 |
| 47 private: | 51 private: |
| 48 ~DesktopNotificationDelegate() override; | 52 ~DesktopNotificationDelegate() override; |
| 49 | 53 |
| 50 std::string id_; | 54 const std::string id_; |
| 51 base::Closure button_click_callback_; | 55 const base::Closure button_click_callback_; |
| 52 | 56 |
| 53 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationDelegate); | 57 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationDelegate); |
| 54 }; | 58 }; |
| 55 | 59 |
| 56 DesktopNotificationDelegate::DesktopNotificationDelegate( | 60 DesktopNotificationDelegate::DesktopNotificationDelegate( |
| 57 const std::string& id, | 61 const std::string& id, |
| 58 const base::Closure& button_click_callback) | 62 const base::Closure& button_click_callback) |
| 59 : id_(id), button_click_callback_(button_click_callback) { | 63 : id_(id), button_click_callback_(button_click_callback) { |
| 60 } | 64 } |
| 61 | 65 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 86 | 90 |
| 87 ConsumerManagementNotifier::~ConsumerManagementNotifier() { | 91 ConsumerManagementNotifier::~ConsumerManagementNotifier() { |
| 88 } | 92 } |
| 89 | 93 |
| 90 void ConsumerManagementNotifier::Shutdown() { | 94 void ConsumerManagementNotifier::Shutdown() { |
| 91 consumer_management_service_->RemoveObserver(this); | 95 consumer_management_service_->RemoveObserver(this); |
| 92 } | 96 } |
| 93 | 97 |
| 94 void ConsumerManagementNotifier::OnConsumerManagementStatusChanged() { | 98 void ConsumerManagementNotifier::OnConsumerManagementStatusChanged() { |
| 95 if (consumer_management_service_->HasPendingEnrollmentNotification()) { | 99 if (consumer_management_service_->HasPendingEnrollmentNotification()) { |
| 96 ConsumerManagementService::EnrollmentStage stage = | 100 const ConsumerManagementService::EnrollmentStage stage = |
| 97 consumer_management_service_->GetEnrollmentStage(); | 101 consumer_management_service_->GetEnrollmentStage(); |
| 98 // Reset the enrollment stage so that we won't show the same notification, | 102 // Reset the enrollment stage so that we won't show the same notification, |
| 99 // again. | 103 // again. |
| 100 consumer_management_service_->SetEnrollmentStage( | 104 consumer_management_service_->SetEnrollmentStage( |
| 101 ConsumerManagementService::ENROLLMENT_STAGE_NONE); | 105 ConsumerManagementService::ENROLLMENT_STAGE_NONE); |
| 102 ShowDesktopNotification(stage); | 106 ShowDesktopNotification(stage); |
| 103 } | 107 } |
| 104 } | 108 } |
| 105 | 109 |
| 106 void ConsumerManagementNotifier::ShowDesktopNotification( | 110 void ConsumerManagementNotifier::ShowDesktopNotification( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void ConsumerManagementNotifier::TryEnrollmentAgain() const { | 167 void ConsumerManagementNotifier::TryEnrollmentAgain() const { |
| 164 const GURL base_url(chrome::kChromeUISettingsURL); | 168 const GURL base_url(chrome::kChromeUISettingsURL); |
| 165 const GURL url = base_url.Resolve(kConsumerManagementOverlay); | 169 const GURL url = base_url.Resolve(kConsumerManagementOverlay); |
| 166 | 170 |
| 167 chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK); | 171 chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK); |
| 168 params.disposition = NEW_FOREGROUND_TAB; | 172 params.disposition = NEW_FOREGROUND_TAB; |
| 169 chrome::Navigate(¶ms); | 173 chrome::Navigate(¶ms); |
| 170 } | 174 } |
| 171 | 175 |
| 172 } // namespace policy | 176 } // namespace policy |
| OLD | NEW |