OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/browser/transition_request_manager.h" | 5 #include "content/browser/transition_request_manager.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
| 8 #include "base/strings/stringprintf.h" |
8 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/common/child_process_host.h" |
| 11 #include "content/public/common/url_constants.h" |
| 12 #include "url/gurl.h" |
9 | 13 |
10 namespace content { | 14 namespace content { |
11 | 15 |
12 bool TransitionRequestManager::HasPendingTransitionRequest( | 16 bool TransitionRequestManager::HasPendingTransitionRequest( |
13 int process_id, | 17 int process_id, |
14 int render_frame_id) { | 18 int render_frame_id) { |
15 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 19 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
16 | 20 |
17 std::pair<int, int> key(process_id, render_frame_id); | 21 std::pair<int, int> key(process_id, render_frame_id); |
18 return (pending_transition_frames_.find(key) != | 22 return (pending_transition_frames_.find(key) != |
19 pending_transition_frames_.end()); | 23 pending_transition_frames_.end()); |
20 } | 24 } |
21 | 25 |
22 void TransitionRequestManager::SetHasPendingTransitionRequest( | 26 void TransitionRequestManager::SetHasPendingTransitionRequest( |
23 int process_id, | 27 int process_id, |
24 int render_frame_id, | 28 int render_frame_id, |
25 bool has_pending) { | 29 bool has_pending) { |
26 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 30 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
27 | 31 |
28 std::pair<int, int> key(process_id, render_frame_id); | 32 std::pair<int, int> key(process_id, render_frame_id); |
29 if (has_pending) { | 33 if (has_pending) { |
30 pending_transition_frames_.insert(key); | 34 pending_transition_frames_.insert(key); |
31 } else { | 35 } else { |
32 pending_transition_frames_.erase(key); | 36 pending_transition_frames_.erase(key); |
33 } | 37 } |
34 } | 38 } |
35 | 39 |
36 TransitionRequestManager::TransitionRequestManager() { | 40 void TransitionRequestManager::AddPendingTransitionProcessID(const GURL& token, |
| 41 int process_id) { |
| 42 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 43 transition_process_ids_[token.spec()] = process_id; |
| 44 } |
| 45 |
| 46 void TransitionRequestManager::ClearPendingTransitionProcessID( |
| 47 const GURL& token) { |
| 48 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 49 transition_process_ids_.erase(token.spec()); |
| 50 } |
| 51 |
| 52 int TransitionRequestManager::GetPendingTransitionProcessIDByToken( |
| 53 const GURL& token) { |
| 54 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 55 ProcessIDMap::iterator it = transition_process_ids_.find(token.spec()); |
| 56 if (it == transition_process_ids_.end()) |
| 57 return content::ChildProcessHost::kInvalidUniqueID; |
| 58 return it->second; |
| 59 } |
| 60 |
| 61 GURL TransitionRequestManager::CreateTransitionURL() { |
| 62 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 63 transition_unique_ids_++; |
| 64 return GURL(base::StringPrintf( |
| 65 "%s:%x", kNavigationTransitionScheme, transition_unique_ids_)); |
| 66 } |
| 67 |
| 68 TransitionRequestManager::TransitionRequestManager() |
| 69 : transition_unique_ids_(0) { |
37 } | 70 } |
38 | 71 |
39 TransitionRequestManager::~TransitionRequestManager() { | 72 TransitionRequestManager::~TransitionRequestManager() { |
40 } | 73 } |
41 | 74 |
42 // static | 75 // static |
43 TransitionRequestManager* TransitionRequestManager::GetInstance() { | 76 TransitionRequestManager* TransitionRequestManager::GetInstance() { |
44 return Singleton<TransitionRequestManager>::get(); | 77 return Singleton<TransitionRequestManager>::get(); |
45 } | 78 } |
46 | 79 |
47 } // namespace content | 80 } // namespace content |
OLD | NEW |