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

Side by Side Diff: components/password_manager/core/browser/affiliation_backend.h

Issue 947563002: Add prefetch support to AffiliationBackend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove 'stale' accessor, cleaned up timelines for tests, extended/fixed some tests. Created 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_BACKEND_H_ 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_BACKEND_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_BACKEND_H_ 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_BACKEND_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 23 matching lines...) Expand all
34 class AffiliationFetcher; 34 class AffiliationFetcher;
35 class FacetManager; 35 class FacetManager;
36 36
37 // The AffiliationBackend is the part of the AffiliationService that lives on a 37 // The AffiliationBackend is the part of the AffiliationService that lives on a
38 // background thread suitable for performing blocking I/O. As most tasks require 38 // background thread suitable for performing blocking I/O. As most tasks require
39 // I/O, the backend ends up doing most of the work for the AffiliationService; 39 // I/O, the backend ends up doing most of the work for the AffiliationService;
40 // the latter being just a thin layer that delegates most tasks to the backend. 40 // the latter being just a thin layer that delegates most tasks to the backend.
41 // 41 //
42 // This class is not thread-safe, but it is fine to construct it on one thread 42 // This class is not thread-safe, but it is fine to construct it on one thread
43 // and then transfer it to the background thread for the rest of its life. 43 // and then transfer it to the background thread for the rest of its life.
44 // Initialize() must be called already on the background thread. 44 // Initialize() must be called already on the final (background) thread.
45 class AffiliationBackend : public FacetManagerHost, 45 class AffiliationBackend : public FacetManagerHost,
46 public AffiliationFetcherDelegate { 46 public AffiliationFetcherDelegate {
47 public: 47 public:
48 // Constructs an instance that will use |request_context_getter| for all 48 // Constructs an instance that will use |request_context_getter| for all
49 // network requests, and will rely on |time_source| to tell the current time, 49 // network requests, and will rely on |time_source| to tell the current time,
50 // which is expected to always be strictly greater than the NULL time. 50 // which is expected to always be no less than the Unix epoch.
51 // Construction is very cheap, expensive steps are deferred to Initialize(). 51 // Construction is very cheap, expensive steps are deferred to Initialize().
52 AffiliationBackend( 52 AffiliationBackend(
53 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 53 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
54 scoped_ptr<base::Clock> time_source); 54 scoped_ptr<base::Clock> time_source);
55 ~AffiliationBackend() override; 55 ~AffiliationBackend() override;
56 56
57 // Performs the I/O-heavy part of initialization. The database to cache 57 // Performs the I/O-heavy part of initialization. The database used to cache
58 // affiliation information locally will be opened/created at |db_path|. 58 // affiliation information locally will be opened/created at |db_path|.
59 void Initialize(const base::FilePath& db_path); 59 void Initialize(const base::FilePath& db_path);
60 60
61 // Implementations for methods of the same name in AffiliationService. They 61 // Implementations for methods of the same name in AffiliationService. They
62 // are not documented here again. See affiliation_service.h for details: 62 // are not documented here again. See affiliation_service.h for details:
63 void GetAffiliations( 63 void GetAffiliations(
64 const FacetURI& facet_uri, 64 const FacetURI& facet_uri,
65 bool cached_only, 65 bool cached_only,
66 const AffiliationService::ResultCallback& callback, 66 const AffiliationService::ResultCallback& callback,
67 const scoped_refptr<base::TaskRunner>& callback_task_runner); 67 const scoped_refptr<base::TaskRunner>& callback_task_runner);
68 void Prefetch(const FacetURI& facet_uri, const base::Time& keep_fresh_until); 68 void Prefetch(const FacetURI& facet_uri, const base::Time& keep_fresh_until);
69 void CancelPrefetch(const FacetURI& facet_uri, 69 void CancelPrefetch(const FacetURI& facet_uri,
70 const base::Time& keep_fresh_until); 70 const base::Time& keep_fresh_until);
71 void TrimCache(); 71 void TrimCache();
72 72
73 private: 73 private:
74 friend class AffiliationBackendTest;
75
76 // Retrieves the FacetManager corresponding to |facet_uri|, creating it and
77 // storing it into |facet_managers_| if it did not exist.
78 FacetManager* GetOrCreateFacetManager(const FacetURI& facet_uri);
79
74 // Collects facet URIs that require fetching and issues a network request 80 // Collects facet URIs that require fetching and issues a network request
75 // against the Affiliation API to fetch corresponding affiliation information. 81 // against the Affiliation API to fetch corresponding affiliation information.
76 void SendNetworkRequest(); 82 void SendNetworkRequest();
77 83
84 // Scheduled by RequestNotificationAtTime() to be called back at times when a
85 // FacetManager needs to be notified.
86 void OnSendNotification(const FacetURI& facet_uri);
87
78 // FacetManagerHost: 88 // FacetManagerHost:
79 base::Time GetCurrentTime() override;
80 base::Time ReadLastUpdateTimeFromDatabase(const FacetURI& facet_uri) override;
81 bool ReadAffiliationsFromDatabase( 89 bool ReadAffiliationsFromDatabase(
82 const FacetURI& facet_uri, 90 const FacetURI& facet_uri,
83 AffiliatedFacetsWithUpdateTime* affiliations) override; 91 AffiliatedFacetsWithUpdateTime* affiliations) override;
84 void SignalNeedNetworkRequest() override; 92 void SignalNeedNetworkRequest() override;
93 void RequestNotificationAtTime(const FacetURI& facet_uri,
94 base::Time time) override;
85 95
86 // AffiliationFetcherDelegate: 96 // AffiliationFetcherDelegate:
87 void OnFetchSucceeded( 97 void OnFetchSucceeded(
88 scoped_ptr<AffiliationFetcherDelegate::Result> result) override; 98 scoped_ptr<AffiliationFetcherDelegate::Result> result) override;
89 void OnFetchFailed() override; 99 void OnFetchFailed() override;
90 void OnMalformedResponse() override; 100 void OnMalformedResponse() override;
91 101
102 // Used only for testing.
103 size_t facet_manager_count_for_testing() { return facet_managers_.size(); }
104
92 // Created in Initialize(), and ensures that all subsequent methods are called 105 // Created in Initialize(), and ensures that all subsequent methods are called
93 // on the same thread. 106 // on the same thread.
94 scoped_ptr<base::ThreadChecker> thread_checker_; 107 scoped_ptr<base::ThreadChecker> thread_checker_;
95 108
96 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 109 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
97 110
98 // Will always return a Now() that is strictly greater than the NULL time. 111 // Will always return a Now() that is strictly greater than the NULL time.
99 scoped_ptr<base::Clock> clock_; 112 scoped_ptr<base::Clock> clock_;
100 113
101 scoped_ptr<AffiliationDatabase> cache_; 114 scoped_ptr<AffiliationDatabase> cache_;
102 scoped_ptr<AffiliationFetcher> fetcher_; 115 scoped_ptr<AffiliationFetcher> fetcher_;
103 116
104 // Contains a FacetManager for each facet URI that need ongoing attention. To 117 // Contains a FacetManager for each facet URI that need ongoing attention. To
105 // save memory, managers are discarded as soon as they become redundant. 118 // save memory, managers are discarded as soon as they become redundant.
106 base::ScopedPtrHashMap<FacetURI, FacetManager> facet_managers_; 119 base::ScopedPtrHashMap<FacetURI, FacetManager> facet_managers_;
107 120
108 base::WeakPtrFactory<AffiliationBackend> weak_ptr_factory_; 121 base::WeakPtrFactory<AffiliationBackend> weak_ptr_factory_;
109 122
110 DISALLOW_COPY_AND_ASSIGN(AffiliationBackend); 123 DISALLOW_COPY_AND_ASSIGN(AffiliationBackend);
111 }; 124 };
112 125
113 } // namespace password_manager 126 } // namespace password_manager
114 127
115 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_BACKEND_H_ 128 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_BACKEND_H_
OLDNEW
« no previous file with comments | « components/components_tests.gyp ('k') | components/password_manager/core/browser/affiliation_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698