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

Side by Side Diff: components/offline_pages/downloads/download_ui_adapter.cc

Issue 2180973002: [Offline pages] Adapting OfflinePageDownloadBridge to DownloadUIAdapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ui-adapter
Patch Set: Minor updates Created 4 years, 4 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 | « components/offline_pages/downloads/download_ui_adapter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "components/offline_pages/downloads/download_ui_adapter.h" 5 #include "components/offline_pages/downloads/download_ui_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "components/offline_pages/client_namespace_constants.h" 12 #include "components/offline_pages/client_namespace_constants.h"
13 #include "components/offline_pages/downloads/download_ui_item.h" 13 #include "components/offline_pages/downloads/download_ui_item.h"
14 #include "components/offline_pages/offline_page_model.h" 14 #include "components/offline_pages/offline_page_model.h"
15 15
16 namespace offline_pages { 16 namespace offline_pages {
17 17
18 namespace {
19 const char kDownloadUIAdapterKey[] = "download-ui-adapter";
20 }
21
18 DownloadUIAdapter::DownloadUIAdapter(OfflinePageModel* model) 22 DownloadUIAdapter::DownloadUIAdapter(OfflinePageModel* model)
19 : model_(model), 23 : model_(model),
20 is_loaded_(false), 24 is_loaded_(false),
21 weak_ptr_factory_(this) { 25 weak_ptr_factory_(this) {
22 } 26 }
23 27
24 DownloadUIAdapter::~DownloadUIAdapter() { } 28 DownloadUIAdapter::~DownloadUIAdapter() { }
25 29
30 // static
31 DownloadUIAdapter* DownloadUIAdapter::FromOfflinePageModel(
32 OfflinePageModel* offline_page_model) {
33 DownloadUIAdapter* adapter = static_cast<DownloadUIAdapter*>(
34 offline_page_model->GetUserData(kDownloadUIAdapterKey));
35 if (!adapter) {
36 adapter = new DownloadUIAdapter(offline_page_model);
37 offline_page_model->SetUserData(kDownloadUIAdapterKey, adapter);
38 }
39 return adapter;
40 }
41
26 void DownloadUIAdapter::AddObserver(Observer* observer) { 42 void DownloadUIAdapter::AddObserver(Observer* observer) {
27 DCHECK(observer); 43 DCHECK(observer);
28 if (!observers_.might_have_observers()) 44 if (!observers_.might_have_observers())
29 LoadCache(); 45 LoadCache();
30 observers_.AddObserver(observer); 46 observers_.AddObserver(observer);
31 // If the items are already loaded, post the notification right away. 47 // If the items are already loaded, post the notification right away.
32 // Don't just invoke it from here to avoid reentrancy in the client. 48 // Don't just invoke it from here to avoid reentrancy in the client.
33 if (is_loaded_) { 49 if (is_loaded_) {
34 base::ThreadTaskRunnerHandle::Get()->PostTask( 50 base::ThreadTaskRunnerHandle::Get()->PostTask(
35 FROM_HERE, base::Bind(&DownloadUIAdapter::NotifyItemsLoaded, 51 FROM_HERE, base::Bind(&DownloadUIAdapter::NotifyItemsLoaded,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 153 }
138 } 154 }
139 155
140 bool DownloadUIAdapter::IsVisibleInUI(const OfflinePageItem& page) { 156 bool DownloadUIAdapter::IsVisibleInUI(const OfflinePageItem& page) {
141 // TODO(dimich): set up the right filter here. 157 // TODO(dimich): set up the right filter here.
142 return page.client_id.name_space == kAsyncNamespace && 158 return page.client_id.name_space == kAsyncNamespace &&
143 base::IsValidGUID(page.client_id.id); 159 base::IsValidGUID(page.client_id.id);
144 } 160 }
145 161
146 } // namespace offline_pages 162 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/downloads/download_ui_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698