OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
6 #define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 6 #define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/observer_list.h" |
17 #include "chrome/browser/history/history_types.h" | 19 #include "chrome/browser/history/history_types.h" |
18 #include "chrome/common/instant_types.h" | 20 #include "chrome/common/instant_types.h" |
19 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 21 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
20 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
22 | 24 |
23 class GURL; | 25 class GURL; |
24 class InstantIOContext; | 26 class InstantIOContext; |
| 27 class InstantServiceObserver; |
25 class Profile; | 28 class Profile; |
| 29 class ThemeService; |
26 | 30 |
27 namespace net { | 31 namespace net { |
28 class URLRequest; | 32 class URLRequest; |
29 } | 33 } |
30 | 34 |
31 // Tracks render process host IDs that are associated with Instant. | 35 // Tracks render process host IDs that are associated with Instant. |
32 class InstantService : public BrowserContextKeyedService, | 36 class InstantService : public BrowserContextKeyedService, |
33 public content::NotificationObserver { | 37 public content::NotificationObserver { |
34 public: | 38 public: |
35 explicit InstantService(Profile* profile); | 39 explicit InstantService(Profile* profile); |
36 virtual ~InstantService(); | 40 virtual ~InstantService(); |
37 | 41 |
38 // Add, remove, and query RenderProcessHost IDs that are associated with | 42 // Add, remove, and query RenderProcessHost IDs that are associated with |
39 // Instant processes. | 43 // Instant processes. |
40 void AddInstantProcess(int process_id); | 44 void AddInstantProcess(int process_id); |
41 bool IsInstantProcess(int process_id) const; | 45 bool IsInstantProcess(int process_id) const; |
42 | 46 |
| 47 // Adds/Removes InstantService observers. |
| 48 void AddObserver(InstantServiceObserver* observer); |
| 49 void RemoveObserver(InstantServiceObserver* observer); |
| 50 |
43 #if defined(UNIT_TEST) | 51 #if defined(UNIT_TEST) |
44 int GetInstantProcessCount() const { | 52 int GetInstantProcessCount() const { |
45 return process_ids_.size(); | 53 return process_ids_.size(); |
46 } | 54 } |
47 #endif | 55 #endif |
48 | 56 |
49 // Most visited item API. | 57 // Most visited item API. |
50 | 58 |
51 // Invoked by the InstantController when the Instant page wants to delete a | 59 // Invoked by the InstantController when the Instant page wants to delete a |
52 // Most Visited item. | 60 // Most Visited item. |
53 void DeleteMostVisitedItem(const GURL& url); | 61 void DeleteMostVisitedItem(const GURL& url); |
54 | 62 |
55 // Invoked by the InstantController when the Instant page wants to undo the | 63 // Invoked by the InstantController when the Instant page wants to undo the |
56 // blacklist action. | 64 // blacklist action. |
57 void UndoMostVisitedDeletion(const GURL& url); | 65 void UndoMostVisitedDeletion(const GURL& url); |
58 | 66 |
59 // Invoked by the InstantController when the Instant page wants to undo all | 67 // Invoked by the InstantController when the Instant page wants to undo all |
60 // Most Visited deletions. | 68 // Most Visited deletions. |
61 void UndoAllMostVisitedDeletions(); | 69 void UndoAllMostVisitedDeletions(); |
62 | 70 |
63 // Returns the last added InstantMostVisitedItems. | 71 // Returns the last added InstantMostVisitedItems. |
64 void GetCurrentMostVisitedItems( | 72 void GetCurrentMostVisitedItems( |
65 std::vector<InstantMostVisitedItem>* items) const; | 73 std::vector<InstantMostVisitedItem>* items) const; |
66 | 74 |
| 75 // Invoked by the InstantController to update theme information for NTP. |
| 76 // |
| 77 // TODO(kmadhusu): Invoking this from InstantController shouldn't be |
| 78 // necessary. Investigate more and remove this from here. |
| 79 void UpdateThemeInfo(); |
| 80 |
67 private: | 81 private: |
68 // Overridden from BrowserContextKeyedService: | 82 // Overridden from BrowserContextKeyedService: |
69 virtual void Shutdown() OVERRIDE; | 83 virtual void Shutdown() OVERRIDE; |
70 | 84 |
71 // Overridden from content::NotificationObserver: | 85 // Overridden from content::NotificationObserver: |
72 virtual void Observe(int type, | 86 virtual void Observe(int type, |
73 const content::NotificationSource& source, | 87 const content::NotificationSource& source, |
74 const content::NotificationDetails& details) OVERRIDE; | 88 const content::NotificationDetails& details) OVERRIDE; |
75 | 89 |
76 // Called when we get new most visited items from TopSites, registered as an | 90 // Called when we get new most visited items from TopSites, registered as an |
77 // async callback. Parses them and sends them to the renderer via | 91 // async callback. Parses them and sends them to the renderer via |
78 // SendMostVisitedItems. | 92 // SendMostVisitedItems. |
79 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data); | 93 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data); |
80 | 94 |
| 95 // Theme changed notification handler. |
| 96 void OnThemeChanged(ThemeService* theme_service); |
| 97 |
81 Profile* const profile_; | 98 Profile* const profile_; |
82 | 99 |
83 // The process ids associated with Instant processes. | 100 // The process ids associated with Instant processes. |
84 std::set<int> process_ids_; | 101 std::set<int> process_ids_; |
85 | 102 |
86 // InstantMostVisitedItems sent to the Instant Pages. | 103 // InstantMostVisitedItems sent to the Instant Pages. |
87 std::vector<InstantMostVisitedItem> most_visited_items_; | 104 std::vector<InstantMostVisitedItem> most_visited_items_; |
88 | 105 |
| 106 // Theme-related data for NTP overlay to adopt themes. |
| 107 scoped_ptr<ThemeBackgroundInfo> theme_info_; |
| 108 |
| 109 ObserverList<InstantServiceObserver> observers_; |
| 110 |
89 content::NotificationRegistrar registrar_; | 111 content::NotificationRegistrar registrar_; |
90 | 112 |
91 scoped_refptr<InstantIOContext> instant_io_context_; | 113 scoped_refptr<InstantIOContext> instant_io_context_; |
92 | 114 |
93 // Used for Top Sites async retrieval. | 115 // Used for Top Sites async retrieval. |
94 base::WeakPtrFactory<InstantService> weak_ptr_factory_; | 116 base::WeakPtrFactory<InstantService> weak_ptr_factory_; |
95 | 117 |
96 DISALLOW_COPY_AND_ASSIGN(InstantService); | 118 DISALLOW_COPY_AND_ASSIGN(InstantService); |
97 }; | 119 }; |
98 | 120 |
99 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 121 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
OLD | NEW |