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

Side by Side Diff: components/offline_pages/client_policy_controller.h

Issue 2364253002: [Offline Pages] Adds new policy bits and reverse lookup. (Closed)
Patch Set: Construction order. Created 4 years, 3 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 #ifndef COMPONENTS_OFFLINE_PAGES_CLIENT_POLICY_CONTROLLER_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_CLIENT_POLICY_CONTROLLER_H_
6 #define COMPONENTS_OFFLINE_PAGES_CLIENT_POLICY_CONTROLLER_H_ 6 #define COMPONENTS_OFFLINE_PAGES_CLIENT_POLICY_CONTROLLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory>
11 #include <string> 12 #include <string>
13 #include <vector>
12 14
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "components/offline_pages/offline_page_client_policy.h" 16 #include "components/offline_pages/offline_page_client_policy.h"
15 17
16 namespace offline_pages { 18 namespace offline_pages {
17 19
18 // This is the class which is a singleton for offline page model 20 // This is the class which is a singleton for offline page model
19 // to get client policies based on namespaces. 21 // to get client policies based on namespaces.
20 class ClientPolicyController { 22 class ClientPolicyController {
21 public: 23 public:
22 ClientPolicyController(); 24 ClientPolicyController();
23 ~ClientPolicyController(); 25 ~ClientPolicyController();
24 26
25 // Generates a client policy from the input values. 27 // Generates a client policy from the input values.
26 static const OfflinePageClientPolicy MakePolicy( 28 static const OfflinePageClientPolicy MakePolicy(
27 const std::string& name_space, 29 const std::string& name_space,
28 LifetimePolicy::LifetimeType lifetime_type, 30 LifetimePolicy::LifetimeType lifetime_type,
29 const base::TimeDelta& expiration_period, 31 const base::TimeDelta& expiration_period,
30 size_t page_limit, 32 size_t page_limit,
31 size_t pages_allowed_per_url); 33 size_t pages_allowed_per_url);
32 34
33 // Get the client policy for |name_space|. 35 // Get the client policy for |name_space|.
34 const OfflinePageClientPolicy& GetPolicy(const std::string& name_space) const; 36 const OfflinePageClientPolicy& GetPolicy(const std::string& name_space) const;
35 37
36 // Returns whether pages for |name_space| should be removed on cache reset. 38 // Returns whether pages for |name_space| should be removed on cache reset.
37 bool IsRemovedOnCacheReset(const std::string& name_space) const; 39 bool IsRemovedOnCacheReset(const std::string& name_space) const;
38 40
39 // Returns whether pages for |name_space| are shown in Download UI. 41 // Returns whether pages for |name_space| are shown in Download UI.
40 bool IsSupportedByDownload(const std::string& name_space) const; 42 bool IsSupportedByDownload(const std::string& name_space) const;
43 const std::vector<std::string>& GetNamespacesWithDownloadSupport();
chili 2016/09/23 23:52:43 should these methods be const as well?
dewittj 2016/09/23 23:55:55 Because they are memoizing they are not actually c
chili 2016/09/24 00:00:19 Ah oops forgot about the memoizing bit. darn ^_^
Dmitry Titov 2016/09/24 00:09:29 I think naming-wise, those "get namespaces" method
dewittj 2016/09/26 23:00:31 Done.
44
45 // Returns whether pages for |name_space| are shown in recent tabs UI,
46 // currently only available on NTP.
47 bool IsRecentTab(const std::string& name_space) const;
Dmitry Titov 2016/09/24 00:09:29 What is this feature? Can't understand from the co
dewittj 2016/09/26 23:00:31 Done.
48 const std::vector<std::string>& GetNamespacesForRecentTabs();
49
50 // Returns whether pages for |name_space| should never be shown outside the
51 // tab they were generated in.
52 bool ShouldOnlyBeShownInOriginalTab(const std::string& name_space) const;
Dmitry Titov 2016/09/24 00:09:29 Naming suggestion: IsRestrictedToOriginalTab
dewittj 2016/09/26 23:00:31 Done.
53 const std::vector<std::string>& GetNamespacesToShowInOriginalTab();
41 54
42 private: 55 private:
43 // The map from name_space to a client policy. Will be generated 56 // The map from name_space to a client policy. Will be generated
44 // as pre-defined values for now. 57 // as pre-defined values for now.
45 std::map<std::string, OfflinePageClientPolicy> policies_; 58 std::map<std::string, OfflinePageClientPolicy> policies_;
46 59
60 // Memoizing results.
61 std::unique_ptr<std::vector<std::string>> download_namespace_cache_;
62 std::unique_ptr<std::vector<std::string>> recent_tab_namespace_cache_;
63 std::unique_ptr<std::vector<std::string>> show_in_original_tab_cache_;
64
47 DISALLOW_COPY_AND_ASSIGN(ClientPolicyController); 65 DISALLOW_COPY_AND_ASSIGN(ClientPolicyController);
48 }; 66 };
49 67
50 } // namespace offline_pages 68 } // namespace offline_pages
51 69
52 #endif // COMPONENTS_OFFLINE_PAGES_CLIENT_POLICY_CONTROLLER_H_ 70 #endif // COMPONENTS_OFFLINE_PAGES_CLIENT_POLICY_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698