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

Side by Side Diff: components/previews/core/previews_io_data.h

Issue 2760063002: Add support to previews/ for Server LoFi and LitePages (Closed)
Patch Set: comment fix 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 #ifndef COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ 5 #ifndef COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_
6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ 6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "components/previews/core/previews_decider.h" 17 #include "components/previews/core/previews_decider.h"
18 #include "components/previews/core/previews_experiments.h" 18 #include "components/previews/core/previews_experiments.h"
19 #include "net/nqe/effective_connection_type.h"
19 20
20 class GURL; 21 class GURL;
21 22
22 namespace net { 23 namespace net {
23 class URLRequest; 24 class URLRequest;
24 } 25 }
25 26
26 namespace previews { 27 namespace previews {
27 class PreviewsBlackList; 28 class PreviewsBlackList;
28 class PreviewsOptOutStore; 29 class PreviewsOptOutStore;
29 class PreviewsUIService; 30 class PreviewsUIService;
30 31
31 typedef base::Callback<bool(PreviewsType)> PreviewsIsEnabledCallback; 32 typedef base::Callback<bool(PreviewsType)> PreviewsIsEnabledCallback;
32 33
33 // A class to manage the IO portion of inter-thread communication between 34 // A class to manage the IO portion of inter-thread communication between
34 // previews/ objects. Created on the UI thread, but used only on the IO thread 35 // previews/ objects. Created on the UI thread, but used only on the IO thread
35 // after initialization. 36 // after initialization.
36 class PreviewsIOData : public PreviewsDecider { 37 class PreviewsIOData : public PreviewsDecider {
37 public: 38 public:
38 PreviewsIOData( 39 PreviewsIOData(
39 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, 40 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
40 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); 41 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
41 ~PreviewsIOData() override; 42 ~PreviewsIOData() override;
42 43
43 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to 44 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to
44 // InitializeOnIOThread on the IO thread. 45 // InitializeOnIOThread on the IO thread.
45 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service, 46 virtual void Initialize(
46 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store, 47 base::WeakPtr<PreviewsUIService> previews_ui_service,
47 const PreviewsIsEnabledCallback& is_enabled_callback); 48 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store,
49 const PreviewsIsEnabledCallback& is_enabled_callback);
48 50
49 // Adds a navigation to |url| to the black list with result |opt_out|. 51 // Adds a navigation to |url| to the black list with result |opt_out|.
50 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type); 52 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type);
51 53
52 // Clears the history of the black list between |begin_time| and |end_time|, 54 // Clears the history of the black list between |begin_time| and |end_time|,
53 // both inclusive. 55 // both inclusive.
54 void ClearBlackList(base::Time begin_time, base::Time end_time); 56 void ClearBlackList(base::Time begin_time, base::Time end_time);
55 57
56 // The previews black list that decides whether a navigation can use previews. 58 // The previews black list that decides whether a navigation can use previews.
57 PreviewsBlackList* black_list() const { return previews_black_list_.get(); } 59 PreviewsBlackList* black_list() const { return previews_black_list_.get(); }
58 60
59 // PreviewsDecider implementation: 61 // PreviewsDecider implementation:
60 bool ShouldAllowPreview(const net::URLRequest& request, 62 bool ShouldAllowPreview(const net::URLRequest& request,
61 PreviewsType type) const override; 63 PreviewsType type) const override;
64 bool ShouldAllowPreviewAtECT(
65 const net::URLRequest& request,
66 PreviewsType type,
67 net::EffectiveConnectionType effective_connection_type_threshold)
68 const override;
62 69
63 protected: 70 protected:
64 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with 71 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with
65 // a weak pointer to |this|. Virtualized for testing. 72 // a weak pointer to |this|. Virtualized for testing.
66 virtual void InitializeOnIOThread( 73 virtual void InitializeOnIOThread(
67 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); 74 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store);
68 75
69 private: 76 private:
70 // The UI thread portion of the inter-thread communication for previews. 77 // The UI thread portion of the inter-thread communication for previews.
71 base::WeakPtr<PreviewsUIService> previews_ui_service_; 78 base::WeakPtr<PreviewsUIService> previews_ui_service_;
(...skipping 11 matching lines...) Expand all
83 PreviewsIsEnabledCallback is_enabled_callback_; 90 PreviewsIsEnabledCallback is_enabled_callback_;
84 91
85 base::WeakPtrFactory<PreviewsIOData> weak_factory_; 92 base::WeakPtrFactory<PreviewsIOData> weak_factory_;
86 93
87 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); 94 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData);
88 }; 95 };
89 96
90 } // namespace previews 97 } // namespace previews
91 98
92 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ 99 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_
OLDNEW
« no previous file with comments | « components/previews/core/previews_experiments_unittest.cc ('k') | components/previews/core/previews_io_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698