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

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

Issue 2836863002: [Offline pages] Removing active_request_ from request coordinator (Closed)
Patch Set: Addressing code review feedback and fixing app status change bug 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 completion_callback_ = completion_callback; 27 pending_request_.reset(new SavePageRequest(request));
28 progress_callback_ = progress_callback; 28 completion_callback_ =
29 base::Bind(completion_callback, request, Offliner::RequestStatus::SAVED);
29 30
30 // Post the callback on the run loop. 31 // Post the callback on the run loop.
31 if (enable_callback_) { 32 if (enable_callback_) {
32 const int64_t arbitrary_size = 153LL; 33 const int64_t arbitrary_size = 153LL;
33 base::ThreadTaskRunnerHandle::Get()->PostTask( 34 base::ThreadTaskRunnerHandle::Get()->PostTask(
34 FROM_HERE, base::Bind(progress_callback_, request, arbitrary_size)); 35 FROM_HERE, base::Bind(progress_callback, request, arbitrary_size));
35 base::ThreadTaskRunnerHandle::Get()->PostTask( 36 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
36 FROM_HERE, base::Bind(completion_callback_, request, 37 completion_callback_);
37 Offliner::RequestStatus::SAVED));
38 } 38 }
39 return true; 39 return true;
40 } 40 }
41 41
42 void OfflinerStub::Cancel(const CancelCallback& callback) { 42 bool OfflinerStub::Cancel(const CancelCallback& callback) {
43 cancel_called_ = true; 43 cancel_called_ = true;
44 callback.Run(0LL); 44 if (!pending_request_)
45 return false;
46
47 base::ThreadTaskRunnerHandle::Get()->PostTask(
48 FROM_HERE, base::Bind(callback, *pending_request_.get()));
49 pending_request_.reset();
50 return true;
45 } 51 }
46 52
47 bool OfflinerStub::HandleTimeout(const SavePageRequest& request) { 53 bool OfflinerStub::HandleTimeout(int64_t request_id) {
48 if (snapshot_on_last_retry_) { 54 if (snapshot_on_last_retry_) {
49 base::ThreadTaskRunnerHandle::Get()->PostTask( 55 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
50 FROM_HERE, base::Bind(completion_callback_, request, 56 completion_callback_);
51 Offliner::RequestStatus::SAVED)); 57 pending_request_.reset();
52 return true; 58 return true;
53 } 59 }
54 return false; 60 return false;
55 } 61 }
56 62
57 } // namespace offline_pages 63 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698