Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/ui/webui/ntp/foreign_session_handler.cc

Issue 7554008: Removal of Profile from content part 6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Profile helper function, rebase Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/ntp/foreign_session_handler.h" 5 #include "chrome/browser/ui/webui/ntp/foreign_session_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // Calling foreignSessions with empty list will automatically hide 64 // Calling foreignSessions with empty list will automatically hide
65 // foreign session section. 65 // foreign session section.
66 web_ui_->CallJavascriptFunction("foreignSessions", list_value); 66 web_ui_->CallJavascriptFunction("foreignSessions", list_value);
67 break; 67 break;
68 default: 68 default:
69 NOTREACHED(); 69 NOTREACHED();
70 } 70 }
71 } 71 }
72 72
73 SessionModelAssociator* ForeignSessionHandler::GetModelAssociator() { 73 SessionModelAssociator* ForeignSessionHandler::GetModelAssociator() {
74 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); 74 ProfileSyncService* service =
75 Profile::FromWebUI(web_ui_)->GetProfileSyncService();
75 if (service == NULL) 76 if (service == NULL)
76 return NULL; 77 return NULL;
78
77 // We only want to set the model associator if there is one, and it is done 79 // We only want to set the model associator if there is one, and it is done
78 // syncing sessions. 80 // syncing sessions.
79 SessionModelAssociator* model_associator = service-> 81 SessionModelAssociator* model_associator =
80 GetSessionModelAssociator(); 82 service->GetSessionModelAssociator();
81 if (model_associator == NULL || 83 if (model_associator == NULL ||
82 !service->ShouldPushChanges()) { 84 !service->ShouldPushChanges()) {
83 return NULL; 85 return NULL;
84 } 86 }
85 return web_ui_->GetProfile()->GetProfileSyncService()-> 87 return model_associator;
86 GetSessionModelAssociator();
87 } 88 }
88 89
89 void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) { 90 void ForeignSessionHandler::HandleGetForeignSessions(const ListValue* args) {
90 SessionModelAssociator* associator = GetModelAssociator(); 91 SessionModelAssociator* associator = GetModelAssociator();
91 std::vector<const SyncedSession*> sessions; 92 std::vector<const SyncedSession*> sessions;
92 93
93 if (associator == NULL) { 94 if (associator == NULL) {
94 // Called before associator created, exit. 95 // Called before associator created, exit.
95 return; 96 return;
96 } 97 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 std::string tab_id_str; 158 std::string tab_id_str;
158 SessionID::id_type tab_id = kInvalidId; 159 SessionID::id_type tab_id = kInvalidId;
159 if (num_args == 3 && (!args->GetString(2, &tab_id_str) || 160 if (num_args == 3 && (!args->GetString(2, &tab_id_str) ||
160 !base::StringToInt(tab_id_str, &tab_id))) { 161 !base::StringToInt(tab_id_str, &tab_id))) {
161 LOG(ERROR) << "Failed to extract tab SessionID."; 162 LOG(ERROR) << "Failed to extract tab SessionID.";
162 return; 163 return;
163 } 164 }
164 165
165 SessionModelAssociator* associator = GetModelAssociator(); 166 SessionModelAssociator* associator = GetModelAssociator();
166 167
168 Profile* profile = Profile::FromWebUI(web_ui_);
167 if (tab_id != kInvalidId) { 169 if (tab_id != kInvalidId) {
168 // We don't actually care about |window_num|, this is just a sanity check. 170 // We don't actually care about |window_num|, this is just a sanity check.
169 DCHECK_LT(kInvalidId, window_num); 171 DCHECK_LT(kInvalidId, window_num);
170 const SessionTab* tab; 172 const SessionTab* tab;
171 if (!associator->GetForeignTab(session_string_value, tab_id, &tab)) { 173 if (!associator->GetForeignTab(session_string_value, tab_id, &tab)) {
172 LOG(ERROR) << "Failed to load foreign tab."; 174 LOG(ERROR) << "Failed to load foreign tab.";
173 return; 175 return;
174 } 176 }
175 SessionRestore::RestoreForeignSessionTab(web_ui_->GetProfile(), *tab); 177 SessionRestore::RestoreForeignSessionTab(profile, *tab);
176 } else { 178 } else {
177 std::vector<SessionWindow*> windows; 179 std::vector<SessionWindow*> windows;
178 // Note: we don't own the ForeignSessions themselves. 180 // Note: we don't own the ForeignSessions themselves.
179 if (!associator->GetForeignSession(session_string_value, &windows)) { 181 if (!associator->GetForeignSession(session_string_value, &windows)) {
180 LOG(ERROR) << "ForeignSessionHandler failed to get session data from" 182 LOG(ERROR) << "ForeignSessionHandler failed to get session data from"
181 "SessionModelAssociator."; 183 "SessionModelAssociator.";
182 return; 184 return;
183 } 185 }
184 std::vector<SessionWindow*>::const_iterator iter_begin = windows.begin() + 186 std::vector<SessionWindow*>::const_iterator iter_begin = windows.begin() +
185 ((window_num == kInvalidId) ? 0 : window_num); 187 ((window_num == kInvalidId) ? 0 : window_num);
186 std::vector<SessionWindow*>::const_iterator iter_end = 188 std::vector<SessionWindow*>::const_iterator iter_end =
187 ((window_num == kInvalidId) ? 189 ((window_num == kInvalidId) ?
188 std::vector<SessionWindow*>::const_iterator(windows.end()) : 190 std::vector<SessionWindow*>::const_iterator(windows.end()) :
189 iter_begin+1); 191 iter_begin + 1);
190 SessionRestore::RestoreForeignSessionWindows(web_ui_->GetProfile(), 192 SessionRestore::RestoreForeignSessionWindows(profile, iter_begin, iter_end);
191 iter_begin,
192 iter_end);
193 } 193 }
194 } 194 }
195 195
196 bool ForeignSessionHandler::SessionTabToValue( 196 bool ForeignSessionHandler::SessionTabToValue(
197 const SessionTab& tab, 197 const SessionTab& tab,
198 DictionaryValue* dictionary) { 198 DictionaryValue* dictionary) {
199 if (tab.navigations.empty()) 199 if (tab.navigations.empty())
200 return false; 200 return false;
201 int selected_index = tab.current_navigation_index; 201 int selected_index = tab.current_navigation_index;
202 selected_index = std::max( 202 selected_index = std::max(
(...skipping 30 matching lines...) Expand all
233 return false; 233 return false;
234 dictionary->SetString("type", "window"); 234 dictionary->SetString("type", "window");
235 dictionary->SetDouble("timestamp", 235 dictionary->SetDouble("timestamp",
236 static_cast<double>(window.timestamp.ToInternalValue())); 236 static_cast<double>(window.timestamp.ToInternalValue()));
237 dictionary->SetInteger("sessionId", window.window_id.id()); 237 dictionary->SetInteger("sessionId", window.window_id.id());
238 dictionary->Set("tabs", tab_values.release()); 238 dictionary->Set("tabs", tab_values.release());
239 return true; 239 return true;
240 } 240 }
241 241
242 } // namespace browser_sync 242 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/favicon_webui_handler.cc ('k') | chrome/browser/ui/webui/ntp/most_visited_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698