| 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_IO_CONTEXT_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_INSTANT_IO_CONTEXT_H_ |
| 6 #define CHROME_BROWSER_SEARCH_INSTANT_IO_CONTEXT_H_ | 6 #define CHROME_BROWSER_SEARCH_INSTANT_IO_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // Installs the |instant_io_context| into the UserData of the | 37 // Installs the |instant_io_context| into the UserData of the |
| 38 // |resource_context|. | 38 // |resource_context|. |
| 39 static void SetUserDataOnIO( | 39 static void SetUserDataOnIO( |
| 40 content::ResourceContext* resource_context, | 40 content::ResourceContext* resource_context, |
| 41 scoped_refptr<InstantIOContext> instant_io_context); | 41 scoped_refptr<InstantIOContext> instant_io_context); |
| 42 | 42 |
| 43 // Add and remove RenderProcessHost IDs that are associated with Instant | 43 // Add and remove RenderProcessHost IDs that are associated with Instant |
| 44 // processes. Used to keep process IDs in sync with InstantService. | 44 // processes. Used to keep process IDs in sync with InstantService. |
| 45 static void AddInstantProcessOnIO( | 45 static void AddInstantProcessOnIO( |
| 46 scoped_refptr<InstantIOContext> instant_io_context, | 46 scoped_refptr<InstantIOContext> instant_io_context, |
| 47 int process_id); | 47 int process_id, const GURL& site_url); |
| 48 static void RemoveInstantProcessOnIO( | 48 static void RemoveInstantProcessOnIO( |
| 49 scoped_refptr<InstantIOContext> instant_io_context, | 49 scoped_refptr<InstantIOContext> instant_io_context, |
| 50 int process_id); | 50 int process_id); |
| 51 static void ClearInstantProcessesOnIO( | 51 static void ClearInstantProcessesOnIO( |
| 52 scoped_refptr<InstantIOContext> instant_io_context); | 52 scoped_refptr<InstantIOContext> instant_io_context); |
| 53 | 53 |
| 54 // Associates the |most_visited_item_id| with the |url|. | 54 // Associates the |most_visited_item_id| with the |url|. |
| 55 static void AddMostVisitedItemsOnIO( | 55 static void AddMostVisitedItemsOnIO( |
| 56 scoped_refptr<InstantIOContext> instant_io_context, | 56 scoped_refptr<InstantIOContext> instant_io_context, |
| 57 std::vector<InstantMostVisitedItemIDPair> items); | 57 std::vector<InstantMostVisitedItemIDPair> items); |
| 58 | 58 |
| 59 // Determine if this chrome-search: request is coming from an Instant render | 59 // Determine if this chrome-search: request is coming from an Instant render |
| 60 // process. | 60 // process. |
| 61 static bool ShouldServiceRequest(const net::URLRequest* request); | 61 static bool ShouldServiceRequest(const net::URLRequest* request); |
| 62 | 62 |
| 63 // Returns the expected origin of a request from an Instant process. |
| 64 static std::string GetExpectedOrigin(const net::URLRequest* request); |
| 65 |
| 63 // If there is a mapping for the |most_visited_item_id|, sets |url| and | 66 // If there is a mapping for the |most_visited_item_id|, sets |url| and |
| 64 // returns true. | 67 // returns true. |
| 65 static bool GetURLForMostVisitedItemID( | 68 static bool GetURLForMostVisitedItemID( |
| 66 const net::URLRequest* request, | 69 const net::URLRequest* request, |
| 67 InstantRestrictedID most_visited_item_id, | 70 InstantRestrictedID most_visited_item_id, |
| 68 GURL* url); | 71 GURL* url); |
| 69 | 72 |
| 70 protected: | 73 protected: |
| 71 virtual ~InstantIOContext(); | 74 virtual ~InstantIOContext(); |
| 72 | 75 |
| 73 private: | 76 private: |
| 74 friend class base::RefCountedThreadSafe<InstantIOContext>; | 77 friend class base::RefCountedThreadSafe<InstantIOContext>; |
| 75 | 78 |
| 76 // Check that |process_id| is in the known set of Instant processes, ie. | 79 // Check that |process_id| is in the known set of Instant processes, ie. |
| 77 // |process_ids_|. | 80 // |process_ids_|. |
| 78 bool IsInstantProcess(int process_id) const; | 81 bool IsInstantProcess(int process_id) const; |
| 79 | 82 |
| 83 // Gets the site associated with the given Instant process. |
| 84 std::string GetSiteForInstantProcess(int process_id) const; |
| 85 |
| 80 bool GetURLForMostVisitedItemID(InstantRestrictedID most_visited_item_id, | 86 bool GetURLForMostVisitedItemID(InstantRestrictedID most_visited_item_id, |
| 81 GURL* url) const; | 87 GURL* url) const; |
| 82 | 88 |
| 83 // The process IDs associated with Instant processes. Mirror of the process | 89 // The process IDs associated with Instant processes. Mirror of the process |
| 84 // IDs in InstantService. Duplicated here for synchronous access on the IO | 90 // IDs in InstantService. Duplicated here for synchronous access on the IO |
| 85 // thread. | 91 // thread. |
| 86 std::set<int> process_ids_; | 92 std::set<int> process_ids_; |
| 87 | 93 |
| 94 // The site URLs associated with Instant processes. See |process_ids_|. |
| 95 std::map<int, std::string> process_sites_; |
| 96 |
| 88 // The Most Visited item cache. Mirror of the Most Visited item cache in | 97 // The Most Visited item cache. Mirror of the Most Visited item cache in |
| 89 // InstantService. Duplicated here for synchronous access on the IO thread. | 98 // InstantService. Duplicated here for synchronous access on the IO thread. |
| 90 InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_item_cache_; | 99 InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_item_cache_; |
| 91 | 100 |
| 92 DISALLOW_COPY_AND_ASSIGN(InstantIOContext); | 101 DISALLOW_COPY_AND_ASSIGN(InstantIOContext); |
| 93 }; | 102 }; |
| 94 | 103 |
| 95 #endif // CHROME_BROWSER_SEARCH_INSTANT_IO_CONTEXT_H_ | 104 #endif // CHROME_BROWSER_SEARCH_INSTANT_IO_CONTEXT_H_ |
| OLD | NEW |