| 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 the TopNav code, |
| 100 // registered as an async callback. Parses them and sends them to the renderer |
| 101 // via SendMostVisitedItems. |
| 102 void OnMostVisitedItemsReceived(const history::MostVisitedURLList& data); |
| 103 |
| 104 // Sends a collection of MostVisitedItems to the renderer process via the |
| 105 // InstantController. |
| 106 void SendMostVisitedItems(); |
| 107 |
| 85 Profile* const profile_; | 108 Profile* const profile_; |
| 86 | 109 |
| 87 // The process ids associated with Instant processes. | 110 // The process ids associated with Instant processes. |
| 88 std::set<int> process_ids_; | 111 std::set<int> process_ids_; |
| 89 | 112 |
| 90 // A cache of the InstantMostVisitedItems sent to the Instant Pages. | 113 // A cache of the InstantMostVisitedItems sent to the Instant Pages. |
| 91 InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_item_cache_; | 114 InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_item_cache_; |
| 92 | 115 |
| 93 content::NotificationRegistrar registrar_; | 116 content::NotificationRegistrar registrar_; |
| 94 | 117 |
| 95 scoped_refptr<InstantIOContext> instant_io_context_; | 118 scoped_refptr<InstantIOContext> instant_io_context_; |
| 96 | 119 |
| 120 // Used for Top Sites async retrieval. |
| 121 base::WeakPtrFactory<InstantService> weak_ptr_factory_; |
| 122 |
| 97 DISALLOW_COPY_AND_ASSIGN(InstantService); | 123 DISALLOW_COPY_AND_ASSIGN(InstantService); |
| 98 }; | 124 }; |
| 99 | 125 |
| 100 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ | 126 #endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ |
| OLD | NEW |