| 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_INSTANT_INSTANT_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ |
| 6 #define CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> |
| 8 #include <set> | 9 #include <set> |
| 10 #include <string> |
| 9 | 11 |
| 10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 13 #include "chrome/browser/profiles/profile_keyed_service.h" | 15 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 14 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 16 | 18 |
| 19 class GURL; |
| 17 class InstantIOContext; | 20 class InstantIOContext; |
| 18 class Profile; | 21 class Profile; |
| 19 | 22 |
| 23 namespace net { |
| 24 class URLRequest; |
| 25 } |
| 26 |
| 20 // Tracks render process host IDs that are associated with Instant. | 27 // Tracks render process host IDs that are associated with Instant. |
| 21 class InstantService : public ProfileKeyedService, | 28 class InstantService : public ProfileKeyedService, |
| 22 public content::NotificationObserver { | 29 public content::NotificationObserver { |
| 23 public: | 30 public: |
| 24 explicit InstantService(Profile* profile); | 31 explicit InstantService(Profile* profile); |
| 25 virtual ~InstantService(); | 32 virtual ~InstantService(); |
| 26 | 33 |
| 34 // A utility to translate an Instant path if it is of Most Visited item ID |
| 35 // form. If path is a Most Visited item ID and we have a URL for it, then |
| 36 // this URL is returned in string form. The |path| is a URL fragment |
| 37 // corresponding to the path of url with the leading slash ("/") stripped. |
| 38 // For example, chrome-search://favicon/72 would yield a |path| value of "72", |
| 39 // and since 72 is a valid uint64 the path is translated to a valid url, |
| 40 // "http://bingo.com/", say. |
| 41 static const std::string MaybeTranslateInstantPathOnUI( |
| 42 Profile* profile, const std::string& path); |
| 43 static const std::string MaybeTranslateInstantPathOnIO( |
| 44 const net::URLRequest* request, const std::string& path); |
| 45 static bool IsInstantPath(const GURL& url); |
| 46 |
| 27 // Add, remove, and query RenderProcessHost IDs that are associated with | 47 // Add, remove, and query RenderProcessHost IDs that are associated with |
| 28 // Instant processes. | 48 // Instant processes. |
| 29 void AddInstantProcess(int process_id); | 49 void AddInstantProcess(int process_id); |
| 30 bool IsInstantProcess(int process_id) const; | 50 bool IsInstantProcess(int process_id) const; |
| 31 | 51 |
| 32 #if defined(UNIT_TEST) | 52 #if defined(UNIT_TEST) |
| 33 int GetInstantProcessCount() const { | 53 int GetInstantProcessCount() const { |
| 34 return process_ids_.size(); | 54 return process_ids_.size(); |
| 35 } | 55 } |
| 36 #endif | 56 #endif |
| 37 | 57 |
| 58 // If |url| is known the existing Most Visited item ID is returned. Otherwise |
| 59 // a new Most Visited item ID is associated with the |url| and returned. |
| 60 uint64 AddURL(const GURL& url); |
| 61 |
| 62 // If there is a mapping for the |url|, sets |most_visited_item_id| and |
| 63 // returns true. |
| 64 bool GetMostVisitedItemIDForURL(const GURL& url, |
| 65 uint64* most_visited_item_id); |
| 66 |
| 67 // If there is a mapping for the |most_visited_item_id|, sets |url| and |
| 68 // returns true. |
| 69 bool GetURLForMostVisitedItemId(uint64 most_visited_item_id, GURL* url); |
| 70 |
| 38 private: | 71 private: |
| 39 // Overridden from ProfileKeyedService: | 72 // Overridden from ProfileKeyedService: |
| 40 virtual void Shutdown() OVERRIDE; | 73 virtual void Shutdown() OVERRIDE; |
| 41 | 74 |
| 42 // Overridden from content::NotificationObserver: | 75 // Overridden from content::NotificationObserver: |
| 43 virtual void Observe(int type, | 76 virtual void Observe(int type, |
| 44 const content::NotificationSource& source, | 77 const content::NotificationSource& source, |
| 45 const content::NotificationDetails& details) OVERRIDE; | 78 const content::NotificationDetails& details) OVERRIDE; |
| 46 | 79 |
| 80 // Removes entries of each url in |deleted_urls| from the ID maps. Or all |
| 81 // IDs if |all_history| is true. |deleted_ids| is filled with the newly |
| 82 // deleted Most Visited item IDs. |
| 83 void DeleteHistoryURLs(const std::vector<GURL>& deleted_urls, |
| 84 std::vector<uint64>* deleted_ids); |
| 85 |
| 47 Profile* const profile_; | 86 Profile* const profile_; |
| 48 | 87 |
| 49 // The process ids associated with Instant processes. | 88 // The process ids associated with Instant processes. |
| 50 std::set<int> process_ids_; | 89 std::set<int> process_ids_; |
| 51 | 90 |
| 91 // A mapping of Most Visited IDs to URLs. Used to hide Most Visited and |
| 92 // Favicon URLs from the Instant search provider. |
| 93 uint64 last_most_visited_item_id_; |
| 94 std::map<uint64, GURL> most_visited_item_id_to_url_map_; |
| 95 std::map<GURL, uint64> url_to_most_visited_item_id_map_; |
| 96 |
| 52 content::NotificationRegistrar registrar_; | 97 content::NotificationRegistrar registrar_; |
| 53 | 98 |
| 54 scoped_refptr<InstantIOContext> instant_io_context_; | 99 scoped_refptr<InstantIOContext> instant_io_context_; |
| 55 | 100 |
| 56 DISALLOW_COPY_AND_ASSIGN(InstantService); | 101 DISALLOW_COPY_AND_ASSIGN(InstantService); |
| 57 }; | 102 }; |
| 58 | 103 |
| 59 #endif // CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ | 104 #endif // CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ |
| OLD | NEW |