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 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 16 #include "chrome/browser/history/history_types.h" |
15 #include "chrome/common/instant_restricted_id_cache.h" | 17 #include "chrome/common/instant_restricted_id_cache.h" |
16 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 18 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
17 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
19 | 21 |
20 class GURL; | 22 class GURL; |
21 class InstantIOContext; | 23 class InstantIOContext; |
22 class Profile; | 24 class Profile; |
23 | 25 |
24 namespace net { | 26 namespace net { |
(...skipping 30 matching lines...) Expand all Loading... |
55 return process_ids_.size(); | 57 return process_ids_.size(); |
56 } | 58 } |
57 #endif | 59 #endif |
58 | 60 |
59 // Most visited item API. | 61 // Most visited item API. |
60 | 62 |
61 // Adds |items| to the |most_visited_item_cache_| assigning restricted IDs in | 63 // Adds |items| to the |most_visited_item_cache_| assigning restricted IDs in |
62 // the process. | 64 // the process. |
63 void AddMostVisitedItems(const std::vector<InstantMostVisitedItem>& items); | 65 void AddMostVisitedItems(const std::vector<InstantMostVisitedItem>& items); |
64 | 66 |
| 67 // Invoked by the InstantController when the Instant page wants to delete a |
| 68 // Most Visited item. |
| 69 void DeleteMostVisitedItem(const GURL& url); |
| 70 |
| 71 // Invoked by the InstantController when the Instant page wants to undo the |
| 72 // blacklist action. |
| 73 void UndoMostVisitedDeletion(const GURL& url); |
| 74 |
| 75 // Invoked by the InstantController when the Instant page wants to undo all |
| 76 // Most Visited deletions. |
| 77 void UndoAllMostVisitedDeletions(); |
| 78 |
65 // Returns the last added InstantMostVisitedItems. After the call to | 79 // Returns the last added InstantMostVisitedItems. After the call to |
66 // |AddMostVisitedItems|, the caller should call this to get the items with | 80 // |AddMostVisitedItems|, the caller should call this to get the items with |
67 // the assigned IDs. | 81 // the assigned IDs. |
68 void GetCurrentMostVisitedItems( | 82 void GetCurrentMostVisitedItems( |
69 std::vector<InstantMostVisitedItemIDPair>* items) const; | 83 std::vector<InstantMostVisitedItemIDPair>* items) const; |
70 | 84 |
71 // If the |most_visited_item_id| is found in the cache, sets the |item| to it | |
72 // and returns true. | |
73 bool GetMostVisitedItemForID(InstantRestrictedID most_visited_item_id, | |
74 InstantMostVisitedItem* item) const; | |
75 | |
76 private: | 85 private: |
77 // Overridden from BrowserContextKeyedService: | 86 // Overridden from BrowserContextKeyedService: |
78 virtual void Shutdown() OVERRIDE; | 87 virtual void Shutdown() OVERRIDE; |
79 | 88 |
80 // Overridden from content::NotificationObserver: | 89 // Overridden from content::NotificationObserver: |
81 virtual void Observe(int type, | 90 virtual void Observe(int type, |
82 const content::NotificationSource& source, | 91 const content::NotificationSource& source, |
83 const content::NotificationDetails& details) OVERRIDE; | 92 const content::NotificationDetails& details) OVERRIDE; |
84 | 93 |
| 94 // If the |most_visited_item_id| is found in the cache, sets the |item| to it |
| 95 // and returns true. |
| 96 bool GetMostVisitedItemForID(InstantRestrictedID most_visited_item_id, |
| 97 InstantMostVisitedItem* item) const; |
| 98 |
| 99 // Called when we get new most visited items from TopSites, registered as an |
| 100 // async callback. Parses them and sends them to the renderer via |
| 101 // SendMostVisitedItems. |
| 102 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data); |
| 103 |
85 Profile* const profile_; | 104 Profile* const profile_; |
86 | 105 |
87 // The process ids associated with Instant processes. | 106 // The process ids associated with Instant processes. |
88 std::set<int> process_ids_; | 107 std::set<int> process_ids_; |
89 | 108 |
90 // A cache of the InstantMostVisitedItems sent to the Instant Pages. | 109 // A cache of the InstantMostVisitedItems sent to the Instant Pages. |
91 InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_item_cache_; | 110 InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_item_cache_; |
92 | 111 |
93 content::NotificationRegistrar registrar_; | 112 content::NotificationRegistrar registrar_; |
94 | 113 |
95 scoped_refptr<InstantIOContext> instant_io_context_; | 114 scoped_refptr<InstantIOContext> instant_io_context_; |
96 | 115 |
| 116 // Used for Top Sites async retrieval. |
| 117 base::WeakPtrFactory<InstantService> weak_ptr_factory_; |
| 118 |
97 DISALLOW_COPY_AND_ASSIGN(InstantService); | 119 DISALLOW_COPY_AND_ASSIGN(InstantService); |
98 }; | 120 }; |
99 | 121 |
100 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 122 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
OLD | NEW |