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

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

Issue 2748033002: Revert of Moving previews code from components/ to chrome/ (Closed)
Patch Set: Created 3 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 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"
12 #include "base/macros.h" 11 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
15 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
16 #include "base/time/time.h" 15 #include "base/time/time.h"
17 #include "components/previews/core/previews_decider.h" 16 #include "components/previews/core/previews_decider.h"
18 #include "components/previews/core/previews_experiments.h" 17 #include "components/previews/core/previews_experiments.h"
19 18
20 class GURL; 19 class GURL;
21 20
22 namespace net { 21 namespace net {
23 class URLRequest; 22 class URLRequest;
24 } 23 }
25 24
26 namespace previews { 25 namespace previews {
27 class PreviewsBlackList; 26 class PreviewsBlackList;
28 class PreviewsOptOutStore; 27 class PreviewsOptOutStore;
29 class PreviewsUIService; 28 class PreviewsUIService;
30 29
31 typedef base::Callback<bool(PreviewsType)> PreviewsIsEnabledCallback;
32
33 // A class to manage the IO portion of inter-thread communication between 30 // 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 31 // previews/ objects. Created on the UI thread, but used only on the IO thread
35 // after initialization. 32 // after initialization.
36 class PreviewsIOData : public PreviewsDecider { 33 class PreviewsIOData : public PreviewsDecider {
37 public: 34 public:
38 PreviewsIOData( 35 PreviewsIOData(
39 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, 36 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
40 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); 37 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
41 ~PreviewsIOData() override; 38 ~PreviewsIOData() override;
42 39
43 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to 40 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to
44 // InitializeOnIOThread on the IO thread. 41 // InitializeOnIOThread on the IO thread.
45 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service, 42 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service,
46 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store, 43 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store);
47 const PreviewsIsEnabledCallback& is_enabled_callback);
48 44
49 // Adds a navigation to |url| to the black list with result |opt_out|. 45 // Adds a navigation to |url| to the black list with result |opt_out|.
50 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type); 46 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type);
51 47
52 // Clears the history of the black list between |begin_time| and |end_time|, 48 // Clears the history of the black list between |begin_time| and |end_time|,
53 // both inclusive. 49 // both inclusive.
54 void ClearBlackList(base::Time begin_time, base::Time end_time); 50 void ClearBlackList(base::Time begin_time, base::Time end_time);
55 51
56 // The previews black list that decides whether a navigation can use previews. 52 // The previews black list that decides whether a navigation can use previews.
57 PreviewsBlackList* black_list() const { return previews_black_list_.get(); } 53 PreviewsBlackList* black_list() const { return previews_black_list_.get(); }
(...skipping 14 matching lines...) Expand all
72 68
73 std::unique_ptr<PreviewsBlackList> previews_black_list_; 69 std::unique_ptr<PreviewsBlackList> previews_black_list_;
74 70
75 // The UI and IO thread task runners. |ui_task_runner_| is used to post 71 // The UI and IO thread task runners. |ui_task_runner_| is used to post
76 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from 72 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from
77 // Initialize to InitializeOnIOThread as well as verify that execution is 73 // Initialize to InitializeOnIOThread as well as verify that execution is
78 // happening on the IO thread. 74 // happening on the IO thread.
79 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 75 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
80 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 76 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
81 77
82 // Whether the preview is enabled. Valid after Initialize() is called.
83 PreviewsIsEnabledCallback is_enabled_callback_;
84
85 base::WeakPtrFactory<PreviewsIOData> weak_factory_; 78 base::WeakPtrFactory<PreviewsIOData> weak_factory_;
86 79
87 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); 80 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData);
88 }; 81 };
89 82
90 } // namespace previews 83 } // namespace previews
91 84
92 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ 85 #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