Chromium Code Reviews| 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 #include "components/offline_pages/core/downloads/download_ui_adapter.h" | 5 #include "components/offline_pages/core/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/core/background/request_coordinator.h" | 12 #include "components/offline_pages/core/background/request_coordinator.h" |
| 13 #include "components/offline_pages/core/background/save_page_request.h" | 13 #include "components/offline_pages/core/background/save_page_request.h" |
| 14 #include "components/offline_pages/core/client_namespace_constants.h" | 14 #include "components/offline_pages/core/client_namespace_constants.h" |
| 15 #include "components/offline_pages/core/client_policy_controller.h" | 15 #include "components/offline_pages/core/client_policy_controller.h" |
| 16 #include "components/offline_pages/core/downloads/download_ui_item.h" | 16 #include "components/offline_pages/core/downloads/download_ui_item.h" |
| 17 #include "components/offline_pages/core/offline_page_model.h" | 17 #include "components/offline_pages/core/offline_page_model.h" |
| 18 | 18 |
| 19 namespace { | |
| 20 // Value of this constant doesn't matter, only its address is used. | |
|
fgorski
2017/02/27 16:22:55
Are you not worried that compiler might optimize t
Dmitry Titov
2017/02/27 20:02:17
Shouldn't since the address of this is passed and
| |
| 21 const char kDownloadUIAdapterKey[] = ""; | |
| 22 } | |
| 23 | |
| 19 namespace offline_pages { | 24 namespace offline_pages { |
| 20 | 25 |
| 26 // static | |
| 27 DownloadUIAdapter* DownloadUIAdapter::FromOfflinePageModel( | |
| 28 OfflinePageModel* model) { | |
|
fgorski
2017/02/27 16:22:55
dcheck(model); please
Dmitry Titov
2017/02/27 20:02:17
Done.
| |
| 29 return static_cast<DownloadUIAdapter*>( | |
| 30 model->GetUserData(kDownloadUIAdapterKey)); | |
| 31 } | |
| 32 | |
| 33 // static | |
| 34 void DownloadUIAdapter::AttachToOfflinePageModel(DownloadUIAdapter* adapter, | |
| 35 OfflinePageModel* model) { | |
|
fgorski
2017/02/27 16:22:55
dcheck both please.
Dmitry Titov
2017/02/27 20:02:17
Done.
| |
| 36 model->SetUserData(kDownloadUIAdapterKey, adapter); | |
| 37 } | |
| 38 | |
| 21 DownloadUIAdapter::ItemInfo::ItemInfo(const OfflinePageItem& page) | 39 DownloadUIAdapter::ItemInfo::ItemInfo(const OfflinePageItem& page) |
| 22 : ui_item(base::MakeUnique<DownloadUIItem>(page)), | 40 : ui_item(base::MakeUnique<DownloadUIItem>(page)), |
| 23 is_request(false), | 41 is_request(false), |
| 24 offline_id(page.offline_id), | 42 offline_id(page.offline_id), |
| 25 client_id(page.client_id), | 43 client_id(page.client_id), |
| 26 temporarily_hidden(false) {} | 44 temporarily_hidden(false) {} |
| 27 | 45 |
| 28 DownloadUIAdapter::ItemInfo::ItemInfo(const SavePageRequest& request) | 46 DownloadUIAdapter::ItemInfo::ItemInfo(const SavePageRequest& request) |
| 29 : ui_item(base::MakeUnique<DownloadUIItem>(request)), | 47 : ui_item(base::MakeUnique<DownloadUIItem>(request)), |
| 30 is_request(true), | 48 is_request(true), |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 items_.erase(it); | 335 items_.erase(it); |
| 318 | 336 |
| 319 if (state_ != State::LOADED) | 337 if (state_ != State::LOADED) |
| 320 return; | 338 return; |
| 321 | 339 |
| 322 for (Observer& observer : observers_) | 340 for (Observer& observer : observers_) |
| 323 observer.ItemDeleted(guid); | 341 observer.ItemDeleted(guid); |
| 324 } | 342 } |
| 325 | 343 |
| 326 } // namespace offline_pages | 344 } // namespace offline_pages |
| OLD | NEW |