OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/foreign_session_handler.h" | 5 #include "chrome/browser/ui/webui/foreign_session_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
| 11 #include <utility> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/bind.h" | 14 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
15 #include "base/i18n/time_formatting.h" | 16 #include "base/i18n/time_formatting.h" |
16 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (window.tabs.empty()) | 105 if (window.tabs.empty()) |
105 return nullptr; | 106 return nullptr; |
106 std::unique_ptr<base::ListValue> tab_values(new base::ListValue()); | 107 std::unique_ptr<base::ListValue> tab_values(new base::ListValue()); |
107 // Calculate the last |modification_time| for all entries within a window. | 108 // Calculate the last |modification_time| for all entries within a window. |
108 base::Time modification_time = window.timestamp; | 109 base::Time modification_time = window.timestamp; |
109 for (const ::sessions::SessionTab* tab : window.tabs) { | 110 for (const ::sessions::SessionTab* tab : window.tabs) { |
110 std::unique_ptr<base::DictionaryValue> tab_value(SessionTabToValue(*tab)); | 111 std::unique_ptr<base::DictionaryValue> tab_value(SessionTabToValue(*tab)); |
111 if (tab_value.get()) { | 112 if (tab_value.get()) { |
112 modification_time = std::max(modification_time, | 113 modification_time = std::max(modification_time, |
113 tab->timestamp); | 114 tab->timestamp); |
114 tab_values->Append(tab_value.release()); | 115 tab_values->Append(std::move(tab_value)); |
115 } | 116 } |
116 } | 117 } |
117 if (tab_values->GetSize() == 0) | 118 if (tab_values->GetSize() == 0) |
118 return nullptr; | 119 return nullptr; |
119 std::unique_ptr<base::DictionaryValue> dictionary( | 120 std::unique_ptr<base::DictionaryValue> dictionary( |
120 BuildWindowData(window.timestamp, window.window_id.id())); | 121 BuildWindowData(window.timestamp, window.window_id.id())); |
121 dictionary->Set("tabs", tab_values.release()); | 122 dictionary->Set("tabs", tab_values.release()); |
122 return dictionary; | 123 return dictionary; |
123 } | 124 } |
124 | 125 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 299 |
299 std::unique_ptr<base::ListValue> window_list(new base::ListValue()); | 300 std::unique_ptr<base::ListValue> window_list(new base::ListValue()); |
300 const std::string group_name = | 301 const std::string group_name = |
301 base::FieldTrialList::FindFullName("TabSyncByRecency"); | 302 base::FieldTrialList::FindFullName("TabSyncByRecency"); |
302 if (group_name != "Enabled") { | 303 if (group_name != "Enabled") { |
303 // Order tabs by visual order within window. | 304 // Order tabs by visual order within window. |
304 for (auto map_iter : session->windows) { | 305 for (auto map_iter : session->windows) { |
305 std::unique_ptr<base::DictionaryValue> window_data( | 306 std::unique_ptr<base::DictionaryValue> window_data( |
306 SessionWindowToValue(*map_iter.second)); | 307 SessionWindowToValue(*map_iter.second)); |
307 if (window_data.get()) | 308 if (window_data.get()) |
308 window_list->Append(window_data.release()); | 309 window_list->Append(std::move(window_data)); |
309 } | 310 } |
310 } else { | 311 } else { |
311 // Order tabs by recency. This involves creating a synthetic singleton | 312 // Order tabs by recency. This involves creating a synthetic singleton |
312 // window that contains all the tabs of the session. | 313 // window that contains all the tabs of the session. |
313 base::Time modification_time; | 314 base::Time modification_time; |
314 std::vector<const ::sessions::SessionTab*> tabs; | 315 std::vector<const ::sessions::SessionTab*> tabs; |
315 open_tabs->GetForeignSessionTabs(session_tag, &tabs); | 316 open_tabs->GetForeignSessionTabs(session_tag, &tabs); |
316 std::unique_ptr<base::ListValue> tab_values(new base::ListValue()); | 317 std::unique_ptr<base::ListValue> tab_values(new base::ListValue()); |
317 for (const ::sessions::SessionTab* tab : tabs) { | 318 for (const ::sessions::SessionTab* tab : tabs) { |
318 std::unique_ptr<base::DictionaryValue> tab_value( | 319 std::unique_ptr<base::DictionaryValue> tab_value( |
319 SessionTabToValue(*tab)); | 320 SessionTabToValue(*tab)); |
320 if (tab_value.get()) { | 321 if (tab_value.get()) { |
321 modification_time = std::max(modification_time, tab->timestamp); | 322 modification_time = std::max(modification_time, tab->timestamp); |
322 tab_values->Append(tab_value.release()); | 323 tab_values->Append(std::move(tab_value)); |
323 } | 324 } |
324 } | 325 } |
325 if (tab_values->GetSize() != 0) { | 326 if (tab_values->GetSize() != 0) { |
326 std::unique_ptr<base::DictionaryValue> window_data( | 327 std::unique_ptr<base::DictionaryValue> window_data( |
327 BuildWindowData(modification_time, 1)); | 328 BuildWindowData(modification_time, 1)); |
328 window_data->Set("tabs", tab_values.release()); | 329 window_data->Set("tabs", tab_values.release()); |
329 window_list->Append(window_data.release()); | 330 window_list->Append(std::move(window_data)); |
330 } | 331 } |
331 } | 332 } |
332 | 333 |
333 session_data->Set("windows", window_list.release()); | 334 session_data->Set("windows", window_list.release()); |
334 session_list.Append(session_data.release()); | 335 session_list.Append(std::move(session_data)); |
335 } | 336 } |
336 } | 337 } |
337 base::FundamentalValue tab_sync_enabled(IsTabSyncEnabled()); | 338 base::FundamentalValue tab_sync_enabled(IsTabSyncEnabled()); |
338 web_ui()->CallJavascriptFunctionUnsafe("setForeignSessions", session_list, | 339 web_ui()->CallJavascriptFunctionUnsafe("setForeignSessions", session_list, |
339 tab_sync_enabled); | 340 tab_sync_enabled); |
340 } | 341 } |
341 | 342 |
342 void ForeignSessionHandler::HandleOpenForeignSession( | 343 void ForeignSessionHandler::HandleOpenForeignSession( |
343 const base::ListValue* args) { | 344 const base::ListValue* args) { |
344 size_t num_args = args->GetSize(); | 345 size_t num_args = args->GetSize(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 // collapsed state persists. | 431 // collapsed state persists. |
431 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 432 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
432 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions); | 433 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions); |
433 if (is_collapsed) | 434 if (is_collapsed) |
434 update.Get()->SetBoolean(session_tag, true); | 435 update.Get()->SetBoolean(session_tag, true); |
435 else | 436 else |
436 update.Get()->Remove(session_tag, NULL); | 437 update.Get()->Remove(session_tag, NULL); |
437 } | 438 } |
438 | 439 |
439 } // namespace browser_sync | 440 } // namespace browser_sync |
OLD | NEW |