OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/jumplist_win.h" | 5 #include "chrome/browser/jumplist_win.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 JumpList::JumpList(Profile* profile) | 196 JumpList::JumpList(Profile* profile) |
197 : profile_(profile), | 197 : profile_(profile), |
198 task_id_(base::CancelableTaskTracker::kBadTaskId), | 198 task_id_(base::CancelableTaskTracker::kBadTaskId), |
199 weak_ptr_factory_(this) { | 199 weak_ptr_factory_(this) { |
200 DCHECK(Enabled()); | 200 DCHECK(Enabled()); |
201 // To update JumpList when a tab is added or removed, we add this object to | 201 // To update JumpList when a tab is added or removed, we add this object to |
202 // the observer list of the TabRestoreService class. | 202 // the observer list of the TabRestoreService class. |
203 // When we add this object to the observer list, we save the pointer to this | 203 // When we add this object to the observer list, we save the pointer to this |
204 // TabRestoreService object. This pointer is used when we remove this object | 204 // TabRestoreService object. This pointer is used when we remove this object |
205 // from the observer list. | 205 // from the observer list. |
206 TabRestoreService* tab_restore_service = | 206 sessions::TabRestoreService* tab_restore_service = |
207 TabRestoreServiceFactory::GetForProfile(profile_); | 207 TabRestoreServiceFactory::GetForProfile(profile_); |
208 if (!tab_restore_service) | 208 if (!tab_restore_service) |
209 return; | 209 return; |
210 | 210 |
211 app_id_ = ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()); | 211 app_id_ = ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()); |
212 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); | 212 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); |
213 | 213 |
214 scoped_refptr<history::TopSites> top_sites = | 214 scoped_refptr<history::TopSites> top_sites = |
215 TopSitesFactory::GetForProfile(profile_); | 215 TopSitesFactory::GetForProfile(profile_); |
216 if (top_sites) { | 216 if (top_sites) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 void JumpList::CancelPendingUpdate() { | 255 void JumpList::CancelPendingUpdate() { |
256 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) { | 256 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) { |
257 cancelable_task_tracker_.TryCancel(task_id_); | 257 cancelable_task_tracker_.TryCancel(task_id_); |
258 task_id_ = base::CancelableTaskTracker::kBadTaskId; | 258 task_id_ = base::CancelableTaskTracker::kBadTaskId; |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 void JumpList::Terminate() { | 262 void JumpList::Terminate() { |
263 CancelPendingUpdate(); | 263 CancelPendingUpdate(); |
264 if (profile_) { | 264 if (profile_) { |
265 TabRestoreService* tab_restore_service = | 265 sessions::TabRestoreService* tab_restore_service = |
266 TabRestoreServiceFactory::GetForProfile(profile_); | 266 TabRestoreServiceFactory::GetForProfile(profile_); |
267 if (tab_restore_service) | 267 if (tab_restore_service) |
268 tab_restore_service->RemoveObserver(this); | 268 tab_restore_service->RemoveObserver(this); |
269 scoped_refptr<history::TopSites> top_sites = | 269 scoped_refptr<history::TopSites> top_sites = |
270 TopSitesFactory::GetForProfile(profile_); | 270 TopSitesFactory::GetForProfile(profile_); |
271 if (top_sites) | 271 if (top_sites) |
272 top_sites->RemoveObserver(this); | 272 top_sites->RemoveObserver(this); |
273 registrar_.reset(); | 273 registrar_.reset(); |
274 pref_change_registrar_.reset(); | 274 pref_change_registrar_.reset(); |
275 } | 275 } |
(...skipping 19 matching lines...) Expand all Loading... |
295 link->set_title(!url.title.empty()? url.title : url_string_wide); | 295 link->set_title(!url.title.empty()? url.title : url_string_wide); |
296 most_visited_pages_.push_back(link); | 296 most_visited_pages_.push_back(link); |
297 icon_urls_.push_back(make_pair(url_string, link)); | 297 icon_urls_.push_back(make_pair(url_string, link)); |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 // Send a query that retrieves the first favicon. | 301 // Send a query that retrieves the first favicon. |
302 StartLoadingFavicon(); | 302 StartLoadingFavicon(); |
303 } | 303 } |
304 | 304 |
305 void JumpList::TabRestoreServiceChanged(TabRestoreService* service) { | 305 void JumpList::TabRestoreServiceChanged(sessions::TabRestoreService* service) { |
306 // if we have a pending handle request, cancel it here (it is out of date). | 306 // if we have a pending handle request, cancel it here (it is out of date). |
307 CancelPendingUpdate(); | 307 CancelPendingUpdate(); |
308 | 308 |
309 // local list to pass to methods | 309 // local list to pass to methods |
310 ShellLinkItemList temp_list; | 310 ShellLinkItemList temp_list; |
311 | 311 |
312 // Create a list of ShellLinkItems from the "Recently Closed" pages. | 312 // Create a list of ShellLinkItems from the "Recently Closed" pages. |
313 // As noted above, we create a ShellLinkItem objects with the following | 313 // As noted above, we create a ShellLinkItem objects with the following |
314 // parameters. | 314 // parameters. |
315 // * arguments | 315 // * arguments |
316 // The last URL of the tab object. | 316 // The last URL of the tab object. |
317 // * title | 317 // * title |
318 // The title of the last URL. | 318 // The title of the last URL. |
319 // * icon | 319 // * icon |
320 // An empty string. This value is to be updated in OnFaviconDataAvailable(). | 320 // An empty string. This value is to be updated in OnFaviconDataAvailable(). |
321 // This code is copied from | 321 // This code is copied from |
322 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. | 322 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. |
323 const int kRecentlyClosedCount = 4; | 323 const int kRecentlyClosedCount = 4; |
324 TabRestoreService* tab_restore_service = | 324 sessions::TabRestoreService* tab_restore_service = |
325 TabRestoreServiceFactory::GetForProfile(profile_); | 325 TabRestoreServiceFactory::GetForProfile(profile_); |
326 const TabRestoreService::Entries& entries = tab_restore_service->entries(); | 326 const sessions::TabRestoreService::Entries& entries = |
327 for (TabRestoreService::Entries::const_iterator it = entries.begin(); | 327 tab_restore_service->entries(); |
| 328 for (sessions::TabRestoreService::Entries::const_iterator it = |
| 329 entries.begin(); |
328 it != entries.end(); ++it) { | 330 it != entries.end(); ++it) { |
329 const TabRestoreService::Entry* entry = *it; | 331 const sessions::TabRestoreService::Entry* entry = *it; |
330 if (entry->type == TabRestoreService::TAB) { | 332 if (entry->type == sessions::TabRestoreService::TAB) { |
331 AddTab(static_cast<const TabRestoreService::Tab*>(entry), | 333 AddTab(static_cast<const sessions::TabRestoreService::Tab*>(entry), |
332 &temp_list, kRecentlyClosedCount); | 334 &temp_list, kRecentlyClosedCount); |
333 } else if (entry->type == TabRestoreService::WINDOW) { | 335 } else if (entry->type == sessions::TabRestoreService::WINDOW) { |
334 AddWindow(static_cast<const TabRestoreService::Window*>(entry), | 336 AddWindow(static_cast<const sessions::TabRestoreService::Window*>(entry), |
335 &temp_list, kRecentlyClosedCount); | 337 &temp_list, kRecentlyClosedCount); |
336 } | 338 } |
337 } | 339 } |
338 // Lock recently_closed_pages and copy temp_list into it. | 340 // Lock recently_closed_pages and copy temp_list into it. |
339 { | 341 { |
340 base::AutoLock auto_lock(list_lock_); | 342 base::AutoLock auto_lock(list_lock_); |
341 recently_closed_pages_ = temp_list; | 343 recently_closed_pages_ = temp_list; |
342 } | 344 } |
343 | 345 |
344 // Send a query that retrieves the first favicon. | 346 // Send a query that retrieves the first favicon. |
345 StartLoadingFavicon(); | 347 StartLoadingFavicon(); |
346 } | 348 } |
347 | 349 |
348 void JumpList::TabRestoreServiceDestroyed(TabRestoreService* service) { | 350 void JumpList::TabRestoreServiceDestroyed( |
349 } | 351 sessions::TabRestoreService* service) {} |
350 | 352 |
351 bool JumpList::AddTab(const TabRestoreService::Tab* tab, | 353 bool JumpList::AddTab(const sessions::TabRestoreService::Tab* tab, |
352 ShellLinkItemList* list, | 354 ShellLinkItemList* list, |
353 size_t max_items) { | 355 size_t max_items) { |
354 // This code adds the URL and the title strings of the given tab to the | 356 // This code adds the URL and the title strings of the given tab to the |
355 // specified list. | 357 // specified list. |
356 if (list->size() >= max_items) | 358 if (list->size() >= max_items) |
357 return false; | 359 return false; |
358 | 360 |
359 scoped_refptr<ShellLinkItem> link = CreateShellLink(); | 361 scoped_refptr<ShellLinkItem> link = CreateShellLink(); |
360 const sessions::SerializedNavigationEntry& current_navigation = | 362 const sessions::SerializedNavigationEntry& current_navigation = |
361 tab->navigations.at(tab->current_navigation_index); | 363 tab->navigations.at(tab->current_navigation_index); |
362 std::string url = current_navigation.virtual_url().spec(); | 364 std::string url = current_navigation.virtual_url().spec(); |
363 link->GetCommandLine()->AppendArgNative(base::UTF8ToWide(url)); | 365 link->GetCommandLine()->AppendArgNative(base::UTF8ToWide(url)); |
364 link->GetCommandLine()->AppendSwitchASCII( | 366 link->GetCommandLine()->AppendSwitchASCII( |
365 switches::kWinJumplistAction, jumplist::kRecentlyClosedCategory); | 367 switches::kWinJumplistAction, jumplist::kRecentlyClosedCategory); |
366 link->set_title(current_navigation.title()); | 368 link->set_title(current_navigation.title()); |
367 list->push_back(link); | 369 list->push_back(link); |
368 icon_urls_.push_back(make_pair(url, link)); | 370 icon_urls_.push_back(make_pair(url, link)); |
369 return true; | 371 return true; |
370 } | 372 } |
371 | 373 |
372 void JumpList::AddWindow(const TabRestoreService::Window* window, | 374 void JumpList::AddWindow(const sessions::TabRestoreService::Window* window, |
373 ShellLinkItemList* list, | 375 ShellLinkItemList* list, |
374 size_t max_items) { | 376 size_t max_items) { |
375 // This code enumerates al the tabs in the given window object and add their | 377 // This code enumerates al the tabs in the given window object and add their |
376 // URLs and titles to the list. | 378 // URLs and titles to the list. |
377 DCHECK(!window->tabs.empty()); | 379 DCHECK(!window->tabs.empty()); |
378 | 380 |
379 for (size_t i = 0; i < window->tabs.size(); ++i) { | 381 for (size_t i = 0; i < window->tabs.size(); ++i) { |
380 if (!AddTab(&window->tabs[i], list, max_items)) | 382 if (!AddTab(&window->tabs[i], list, max_items)) |
381 return; | 383 return; |
382 } | 384 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 531 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
530 } | 532 } |
531 | 533 |
532 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 534 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
533 ChangeReason change_reason) { | 535 ChangeReason change_reason) { |
534 top_sites->GetMostVisitedURLs( | 536 top_sites->GetMostVisitedURLs( |
535 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 537 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
536 weak_ptr_factory_.GetWeakPtr()), | 538 weak_ptr_factory_.GetWeakPtr()), |
537 false); | 539 false); |
538 } | 540 } |
OLD | NEW |