| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_OFFLINE_PAGES_CLIENT_POLICY_CONTROLLER_H_ | |
| 6 #define COMPONENTS_OFFLINE_PAGES_CLIENT_POLICY_CONTROLLER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <memory> | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/time/time.h" | |
| 16 #include "components/offline_pages/offline_page_client_policy.h" | |
| 17 | |
| 18 namespace offline_pages { | |
| 19 | |
| 20 // This is the class which is a singleton for offline page model | |
| 21 // to get client policies based on namespaces. | |
| 22 class ClientPolicyController { | |
| 23 public: | |
| 24 ClientPolicyController(); | |
| 25 ~ClientPolicyController(); | |
| 26 | |
| 27 // Generates a client policy from the input values. | |
| 28 static const OfflinePageClientPolicy MakePolicy( | |
| 29 const std::string& name_space, | |
| 30 LifetimePolicy::LifetimeType lifetime_type, | |
| 31 const base::TimeDelta& expiration_period, | |
| 32 size_t page_limit, | |
| 33 size_t pages_allowed_per_url); | |
| 34 | |
| 35 // Get the client policy for |name_space|. | |
| 36 const OfflinePageClientPolicy& GetPolicy(const std::string& name_space) const; | |
| 37 | |
| 38 // Returns a list of all known namespaces. | |
| 39 std::vector<std::string> GetAllNamespaces() const; | |
| 40 | |
| 41 // Returns whether pages for |name_space| should be removed on cache reset. | |
| 42 bool IsRemovedOnCacheReset(const std::string& name_space) const; | |
| 43 | |
| 44 // Returns whether pages for |name_space| are shown in Download UI. | |
| 45 bool IsSupportedByDownload(const std::string& name_space) const; | |
| 46 const std::vector<std::string>& GetNamespacesSupportedByDownload() const; | |
| 47 | |
| 48 // Returns whether pages for |name_space| are shown in recent tabs UI, | |
| 49 // currently only available on NTP. | |
| 50 bool IsShownAsRecentlyVisitedSite(const std::string& name_space) const; | |
| 51 const std::vector<std::string>& GetNamespacesShownAsRecentlyVisitedSite() | |
| 52 const; | |
| 53 | |
| 54 // Returns whether pages for |name_space| should never be shown outside the | |
| 55 // tab they were generated in. | |
| 56 bool IsRestrictedToOriginalTab(const std::string& name_space) const; | |
| 57 const std::vector<std::string>& GetNamespacesRestrictedToOriginalTab() const; | |
| 58 | |
| 59 void AddPolicyForTest(const std::string& name_space, | |
| 60 const OfflinePageClientPolicyBuilder& builder); | |
| 61 | |
| 62 private: | |
| 63 // The map from name_space to a client policy. Will be generated | |
| 64 // as pre-defined values for now. | |
| 65 std::map<std::string, OfflinePageClientPolicy> policies_; | |
| 66 | |
| 67 // Memoizing results. | |
| 68 mutable std::unique_ptr<std::vector<std::string>> download_namespace_cache_; | |
| 69 mutable std::unique_ptr<std::vector<std::string>> recent_tab_namespace_cache_; | |
| 70 mutable std::unique_ptr<std::vector<std::string>> show_in_original_tab_cache_; | |
| 71 | |
| 72 DISALLOW_COPY_AND_ASSIGN(ClientPolicyController); | |
| 73 }; | |
| 74 | |
| 75 } // namespace offline_pages | |
| 76 | |
| 77 #endif // COMPONENTS_OFFLINE_PAGES_CLIENT_POLICY_CONTROLLER_H_ | |
| OLD | NEW |