| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_DOWNLOADS_DOWNLOAD_NOTIFYING_OBSERVER_H_ | 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_DOWNLOADS_DOWNLOAD_NOTIFYING_OBSERVER_H_ |
| 6 #define COMPONENTS_OFFLINE_PAGES_CORE_DOWNLOADS_DOWNLOAD_NOTIFYING_OBSERVER_H_ | 6 #define COMPONENTS_OFFLINE_PAGES_CORE_DOWNLOADS_DOWNLOAD_NOTIFYING_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "components/offline_pages/core/background/request_coordinator.h" | 12 #include "components/offline_pages/core/background/request_coordinator.h" |
| 13 #include "components/offline_pages/core/client_policy_controller.h" | 13 #include "components/offline_pages/core/client_policy_controller.h" |
| 14 #include "components/offline_pages/core/downloads/download_ui_item.h" |
| 14 | 15 |
| 15 namespace offline_pages { | 16 namespace offline_pages { |
| 16 | 17 |
| 17 struct ClientId; | 18 struct ClientId; |
| 18 struct OfflinePageDownloadNotifier; | 19 struct OfflinePageDownloadNotifier; |
| 19 class ClientPolicyController; | 20 class ClientPolicyController; |
| 20 class SavePageRequest; | 21 class SavePageRequest; |
| 21 | 22 |
| 22 // Class observing the save page requests and issuing corresponding user | 23 // Class observing the save page requests and issuing corresponding user |
| 23 // notifications as requests are added or updated. | 24 // notifications as requests are added or updated. |
| 24 class DownloadNotifyingObserver : public RequestCoordinator::Observer, | 25 class DownloadNotifyingObserver : public RequestCoordinator::Observer, |
| 25 public base::SupportsUserData::Data { | 26 public base::SupportsUserData::Data { |
| 26 public: | 27 public: |
| 27 ~DownloadNotifyingObserver() override; | 28 ~DownloadNotifyingObserver() override; |
| 28 | 29 |
| 29 static DownloadNotifyingObserver* GetFromRequestCoordinator( | 30 static DownloadNotifyingObserver* GetFromRequestCoordinator( |
| 30 RequestCoordinator* request_coordinator); | 31 RequestCoordinator* request_coordinator); |
| 31 static void CreateAndStartObserving( | 32 static void CreateAndStartObserving( |
| 32 RequestCoordinator* request_coordinator, | 33 RequestCoordinator* request_coordinator, |
| 33 std::unique_ptr<OfflinePageDownloadNotifier> notifier); | 34 std::unique_ptr<OfflinePageDownloadNotifier> notifier); |
| 34 | 35 |
| 35 // RequestCoordinator::Observer implementation: | 36 // RequestCoordinator::Observer implementation: |
| 36 void OnAdded(const SavePageRequest& request) override; | 37 void OnAdded(const SavePageRequest& request) override; |
| 37 void OnChanged(const SavePageRequest& request) override; | 38 void OnChanged(const SavePageRequest& request) override; |
| 38 void OnCompleted( | 39 void OnCompleted( |
| 39 const SavePageRequest& request, | 40 const SavePageRequest& request, |
| 40 RequestCoordinator::BackgroundSavePageResult status) override; | 41 RequestCoordinator::BackgroundSavePageResult status) override; |
| 42 void OnNetworkProgress(const SavePageRequest& request, |
| 43 int64_t received_bytes) override; |
| 41 | 44 |
| 42 private: | 45 private: |
| 43 friend class DownloadNotifyingObserverTest; | 46 friend class DownloadNotifyingObserverTest; |
| 44 | 47 |
| 45 DownloadNotifyingObserver( | 48 DownloadNotifyingObserver( |
| 46 std::unique_ptr<OfflinePageDownloadNotifier> notifier, | 49 std::unique_ptr<OfflinePageDownloadNotifier> notifier, |
| 47 ClientPolicyController* policy_controller); | 50 ClientPolicyController* policy_controller); |
| 48 | 51 |
| 49 bool IsVisibleInUI(const ClientId& id); | 52 bool IsVisibleInUI(const ClientId& id); |
| 50 | 53 |
| 51 void NotifyRequestStateChange(const SavePageRequest& request); | 54 void NotifyRequestStateChange(const SavePageRequest& request); |
| 52 | 55 |
| 53 // Used to issue notifications related to save page requests. | 56 // Used to issue notifications related to save page requests. |
| 54 std::unique_ptr<OfflinePageDownloadNotifier> notifier_; | 57 std::unique_ptr<OfflinePageDownloadNotifier> notifier_; |
| 55 // Used to determine policy-related permissions. Not owned. | 58 // Used to determine policy-related permissions. Not owned. |
| 56 ClientPolicyController* policy_controller_; | 59 ClientPolicyController* policy_controller_; |
| 57 | 60 |
| 58 DISALLOW_COPY_AND_ASSIGN(DownloadNotifyingObserver); | 61 DISALLOW_COPY_AND_ASSIGN(DownloadNotifyingObserver); |
| 59 }; | 62 }; |
| 60 | 63 |
| 61 } // namespace offline_pages | 64 } // namespace offline_pages |
| 62 | 65 |
| 63 #endif // COMPONENTS_OFFLINE_PAGES_CORE_DOWNLOADS_DOWNLOAD_NOTIFYING_OBSERVER_H
_ | 66 #endif // COMPONENTS_OFFLINE_PAGES_CORE_DOWNLOADS_DOWNLOAD_NOTIFYING_OBSERVER_H
_ |
| OLD | NEW |