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

Side by Side Diff: components/offline_pages/core/background/offliner_stub.cc

Issue 2736843002: Fix the Download Notifications for Offline Pages to indicate bytes loaded. (Closed)
Patch Set: more fixes to more tests. Created 3 years, 9 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
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/core/background/offliner_stub.h" 5 #include "components/offline_pages/core/background/offliner_stub.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/threading/thread_task_runner_handle.h" 8 #include "base/threading/thread_task_runner_handle.h"
9 #include "components/offline_pages/core/background/save_page_request.h" 9 #include "components/offline_pages/core/background/save_page_request.h"
10 10
11 namespace offline_pages { 11 namespace offline_pages {
12 12
13 OfflinerStub::OfflinerStub() 13 OfflinerStub::OfflinerStub()
14 : disable_loading_(false), 14 : disable_loading_(false),
15 enable_callback_(false), 15 enable_callback_(false),
16 cancel_called_(false), 16 cancel_called_(false),
17 snapshot_on_last_retry_(false) {} 17 snapshot_on_last_retry_(false) {}
18 18
19 OfflinerStub::~OfflinerStub() {} 19 OfflinerStub::~OfflinerStub() {}
20 20
21 bool OfflinerStub::LoadAndSave(const SavePageRequest& request, 21 bool OfflinerStub::LoadAndSave(const SavePageRequest& request,
22 const CompletionCallback& callback) { 22 const CompletionCallback& completion_callback,
23 const ProgressCallback& progress_callback) {
23 if (disable_loading_) 24 if (disable_loading_)
24 return false; 25 return false;
25 26
26 callback_ = callback; 27 completion_callback_ = completion_callback;
28 progress_callback_ = progress_callback;
27 29
28 // Post the callback on the run loop. 30 // Post the callback on the run loop.
29 if (enable_callback_) { 31 if (enable_callback_) {
32 const int64_t arbitrary_size = 153LL;
30 base::ThreadTaskRunnerHandle::Get()->PostTask( 33 base::ThreadTaskRunnerHandle::Get()->PostTask(
31 FROM_HERE, 34 FROM_HERE, base::Bind(progress_callback_, request, arbitrary_size));
32 base::Bind(callback, request, Offliner::RequestStatus::SAVED)); 35 base::ThreadTaskRunnerHandle::Get()->PostTask(
36 FROM_HERE, base::Bind(completion_callback_, request,
37 Offliner::RequestStatus::SAVED));
33 } 38 }
34 return true; 39 return true;
35 } 40 }
36 41
37 void OfflinerStub::Cancel(const CancelCallback& callback) { 42 void OfflinerStub::Cancel(const CancelCallback& callback) {
38 cancel_called_ = true; 43 cancel_called_ = true;
39 callback.Run(0LL); 44 callback.Run(0LL);
40 } 45 }
41 46
42 bool OfflinerStub::HandleTimeout(const SavePageRequest& request) { 47 bool OfflinerStub::HandleTimeout(const SavePageRequest& request) {
43 if (snapshot_on_last_retry_) { 48 if (snapshot_on_last_retry_) {
44 base::ThreadTaskRunnerHandle::Get()->PostTask( 49 base::ThreadTaskRunnerHandle::Get()->PostTask(
45 FROM_HERE, 50 FROM_HERE, base::Bind(completion_callback_, request,
46 base::Bind(callback_, request, Offliner::RequestStatus::SAVED)); 51 Offliner::RequestStatus::SAVED));
47 return true; 52 return true;
48 } 53 }
49 return false; 54 return false;
50 } 55 }
51 56
52 } // namespace offline_pages 57 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698