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

Side by Side Diff: content/browser/background_fetch/background_fetch_data_manager.h

Issue 2708943002: Create the BackgroundFetchBatchManager and initiate a download. (Closed)
Patch Set: Integrated code review comments and added BackgroundFetchDataManager::BatchData which feeds FetchRe… Created 3 years, 10 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_
6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <unordered_map>
11 #include <vector>
10 12
11 #include "base/macros.h" 13 #include "base/macros.h"
12 #include "content/browser/background_fetch/fetch_request.h" 14 #include "content/browser/background_fetch/fetch_request.h"
13 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
14 #include "url/origin.h" 16 #include "url/origin.h"
15 17
16 namespace content { 18 namespace content {
17 19
18 class BackgroundFetchContext; 20 class BackgroundFetchContext;
21 class BatchRequest;
19 22
20 // The BackgroundFetchDataManager keeps track of all of the outstanding requests 23 // The BackgroundFetchDataManager keeps track of all of the outstanding requests
21 // which are in process in the DownloadManager. When Chromium restarts, it is 24 // which are in process in the DownloadManager. When Chromium restarts, it is
22 // responsibile for reconnecting all the in progress downloads with an observer 25 // responsibile for reconnecting all the in progress downloads with an observer
23 // which will keep the metadata up to date. 26 // which will keep the metadata up to date.
24 class CONTENT_EXPORT BackgroundFetchDataManager { 27 class CONTENT_EXPORT BackgroundFetchDataManager {
25 public: 28 public:
26 explicit BackgroundFetchDataManager( 29 explicit BackgroundFetchDataManager(
27 BackgroundFetchContext* background_fetch_context); 30 BackgroundFetchContext* background_fetch_context);
28 ~BackgroundFetchDataManager(); 31 ~BackgroundFetchDataManager();
29 32
33 // The BatchData class provides the interface from the BatchProcessor to the
34 // data storage.
Peter Beverloo 2017/02/24 02:05:16 This comment doesn't really mean anything to me. W
harkness 2017/02/24 11:47:11 We could do that, but I like encapsulating the pie
Peter Beverloo 2017/02/24 15:43:14 That sounds like the sort of improvements we could
35 class BatchData {
36 public:
37 using FetchRequests = std::vector<FetchRequest>;
Peter Beverloo 2017/02/24 02:05:16 This is a source of lots of potential copies too.
harkness 2017/02/24 11:47:11 Done.
38 BatchData();
Peter Beverloo 2017/02/24 02:05:16 Please delete the argument-less constructor (it's
harkness 2017/02/24 11:47:11 Done.
39 BatchData(const BatchRequest& batch_request,
40 const FetchRequests& fetch_requests);
41 ~BatchData();
42 bool FetchRequestComplete(const std::string& fetch_uid);
Peter Beverloo 2017/02/24 02:05:16 All of these are public methods, please document t
Peter Beverloo 2017/02/24 02:05:16 uid -> guid
harkness 2017/02/24 11:47:11 Sorry, I had actually done that, but it looks like
harkness 2017/02/24 11:47:11 Done.
43 const FetchRequest& GetNextFetchRequest();
44 bool IsComplete() const;
45 bool HasRequestsRemaining() const;
46
47 private:
48 FetchRequests fetch_requests_;
49
50 // Map from fetch_uid to index in fetch_requests_. Only currently
51 // outstanding requests should be in this map.
52 std::unordered_map<std::string, int> fetch_request_index_;
53 unsigned long next_fetch_request_ = 0;
Peter Beverloo 2017/02/24 02:05:16 nit: we try to avoid using unsigned types per the
harkness 2017/02/24 11:47:11 Updated to size_t.
54 };
55
30 // Called by BackgroundFetchContext when a new request is started, this will 56 // Called by BackgroundFetchContext when a new request is started, this will
31 // store all of the necessary metadata to track the request. 57 // store all of the necessary metadata to track the request.
32 void CreateRequest(const FetchRequest& fetch_request); 58 BatchData* CreateRequest(const BatchRequest& batch_request,
Peter Beverloo 2017/02/24 02:05:16 Document the memory model of the returned pointer.
harkness 2017/02/24 11:47:11 Done.
59 const std::vector<FetchRequest>& fetch_requests);
33 60
34 private: 61 private:
35 // BackgroundFetchContext owns this BackgroundFetchDataManager, so the 62 // BackgroundFetchContext owns this BackgroundFetchDataManager, so the
36 // DataManager is guaranteed to be destructed before the Context. 63 // DataManager is guaranteed to be destructed before the Context.
37 BackgroundFetchContext* background_fetch_context_; 64 BackgroundFetchContext* background_fetch_context_;
38 65
39 // Map from <sw_registration_id, tag> to the FetchRequest for that tag. 66 // Map from <sw_registration_id, tag> to the FetchRequest for that tag.
40 using FetchIdentifier = std::pair<int64_t, std::string>; 67 using BatchIdentifier = std::pair<int64_t, std::string>;
41 std::map<FetchIdentifier, FetchRequest> fetch_map_; 68 std::map<BatchIdentifier, std::string> service_worker_tag_map_;
69
70 std::map<std::string, BatchData*> batch_map_;
Peter Beverloo 2017/02/24 02:05:16 This must be std::unique_ptr<BatchData>. Manual me
Peter Beverloo 2017/02/24 02:05:16 Document what the index is. Do we depend on orderi
harkness 2017/02/24 11:47:11 Done.
harkness 2017/02/24 11:47:11 Done.
42 71
43 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager); 72 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchDataManager);
44 }; 73 };
45 74
46 } // namespace content 75 } // namespace content
47 76
48 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_ 77 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_DATA_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698