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

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

Issue 2898393002: Split Android-specific dependency from BackgroundLoaderOffliner. Create a subfolder of c/b/offline_… (Closed)
Patch Set: more build fixes Created 3 years, 7 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& completion_callback, 22 const CompletionCallback& completion_callback,
23 const ProgressCallback& progress_callback) { 23 const ProgressCallback& progress_callback) {
24 if (disable_loading_) 24 if (disable_loading_)
25 return false; 25 return false;
26 26
27 pending_request_.reset(new SavePageRequest(request)); 27 pending_request_.reset(new SavePageRequest(request));
28 completion_callback_ = 28 completion_callback_ = completion_callback;
29 base::Bind(completion_callback, request, Offliner::RequestStatus::SAVED);
30 29
31 // Post the callback on the run loop. 30 // Post the callback on the run loop.
32 if (enable_callback_) { 31 if (enable_callback_) {
33 const int64_t arbitrary_size = 153LL; 32 const int64_t arbitrary_size = 153LL;
34 base::ThreadTaskRunnerHandle::Get()->PostTask( 33 base::ThreadTaskRunnerHandle::Get()->PostTask(
35 FROM_HERE, base::Bind(progress_callback, request, arbitrary_size)); 34 FROM_HERE, base::Bind(progress_callback, request, arbitrary_size));
36 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 35 base::ThreadTaskRunnerHandle::Get()->PostTask(
37 completion_callback_); 36 FROM_HERE, base::Bind(completion_callback, *pending_request_.get(),
37 Offliner::RequestStatus::SAVED));
38 } 38 }
39 return true; 39 return true;
40 } 40 }
41 41
42 bool OfflinerStub::Cancel(const CancelCallback& callback) { 42 bool OfflinerStub::Cancel(const CancelCallback& callback) {
43 cancel_called_ = true; 43 cancel_called_ = true;
44 if (!pending_request_) 44 if (!pending_request_)
45 return false; 45 return false;
46 46
47 base::ThreadTaskRunnerHandle::Get()->PostTask( 47 base::ThreadTaskRunnerHandle::Get()->PostTask(
48 FROM_HERE, base::Bind(callback, *pending_request_.get())); 48 FROM_HERE, base::Bind(callback, *pending_request_.get()));
49 pending_request_.reset(); 49 pending_request_.reset();
50 return true; 50 return true;
51 } 51 }
52 52
53 void OfflinerStub::TerminateLoadIfInProgress() {
54 base::ThreadTaskRunnerHandle::Get()->PostTask(
55 FROM_HERE, base::Bind(completion_callback_, *pending_request_.get(),
56 Offliner::RequestStatus::FOREGROUND_CANCELED));
57 pending_request_.reset();
58 }
59
53 bool OfflinerStub::HandleTimeout(int64_t request_id) { 60 bool OfflinerStub::HandleTimeout(int64_t request_id) {
54 if (snapshot_on_last_retry_) { 61 if (snapshot_on_last_retry_) {
55 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 62 base::ThreadTaskRunnerHandle::Get()->PostTask(
56 completion_callback_); 63 FROM_HERE, base::Bind(completion_callback_, *pending_request_.get(),
64 Offliner::RequestStatus::SAVED));
57 pending_request_.reset(); 65 pending_request_.reset();
58 return true; 66 return true;
59 } 67 }
60 return false; 68 return false;
61 } 69 }
62 70
63 } // namespace offline_pages 71 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698