Commit d1b61106 authored by stkhapugin's avatar stkhapugin Committed by Commit bot

[ObjC ARC] Converts a part of ios/chrome/browser/ui/bookmarks:bookmarks to ARC.

Automatically generated ARCMigrate commit (after manually splitting the target).

Converted a relevant unit test alongside this to prevent fiddling with BOOL GetPositionCache(bookmarks::BookmarkModel* model, BookmarkMenuItem** item,  CGFloat* position);
which has an out paramteter |item| that is __autoreleasing in ARC.

Notable issues:None
BUG=624363
TEST=None

Review-Url: https://codereview.chromium.org/2737793003
Cr-Commit-Position: refs/heads/master@{#456054}
parent 160af85b
...@@ -2,6 +2,75 @@ ...@@ -2,6 +2,75 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
source_set("bookmarks_arc") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"bookmark_home_handset_view_controller.h",
"bookmark_home_handset_view_controller.mm",
"bookmark_home_tablet_ntp_controller.h",
"bookmark_home_tablet_ntp_controller.mm",
"bookmark_utils_ios.h",
"bookmark_utils_ios.mm",
]
deps = [
":resources",
"//base",
"//base:i18n",
"//components/bookmarks/browser",
"//components/favicon/core",
"//components/favicon_base",
"//components/pref_registry",
"//components/prefs",
"//components/query_parser",
"//components/signin/core/browser",
"//components/strings",
"//components/undo",
"//components/url_formatter",
"//google_apis",
"//ios/chrome/app/strings",
"//ios/chrome/app/theme",
"//ios/chrome/browser",
"//ios/chrome/browser/bookmarks",
"//ios/chrome/browser/bookmarks:bookmarks_utils",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/favicon",
"//ios/chrome/browser/metrics:metrics_internal",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/alert_coordinator",
"//ios/chrome/browser/ui/bookmarks/bars",
"//ios/chrome/browser/ui/bookmarks/cells",
"//ios/chrome/browser/ui/collection_view",
"//ios/chrome/browser/ui/collection_view/cells",
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/icons",
"//ios/chrome/browser/ui/keyboard",
"//ios/chrome/browser/ui/material_components",
"//ios/chrome/browser/ui/ntp",
"//ios/chrome/browser/undo",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/ui",
"//ios/third_party/material_components_ios",
"//ios/third_party/material_roboto_font_loader_ios",
"//ios/web",
"//skia",
"//ui/base",
"//ui/gfx",
"//url",
]
allow_circular_includes_from = [
"//ios/chrome/browser/ui/bookmarks/bars",
"//ios/chrome/browser/ui/bookmarks/cells",
]
libs = [
"CoreGraphics.framework",
"QuartzCore.framework",
"UIKit.framework",
]
}
source_set("bookmarks") { source_set("bookmarks") {
sources = [ sources = [
"bookmark_collection_cells.h", "bookmark_collection_cells.h",
...@@ -26,11 +95,7 @@ source_set("bookmarks") { ...@@ -26,11 +95,7 @@ source_set("bookmarks") {
"bookmark_folder_table_view_cell.mm", "bookmark_folder_table_view_cell.mm",
"bookmark_folder_view_controller.h", "bookmark_folder_view_controller.h",
"bookmark_folder_view_controller.mm", "bookmark_folder_view_controller.mm",
"bookmark_home_handset_view_controller.h",
"bookmark_home_handset_view_controller.mm",
"bookmark_home_primary_view.h", "bookmark_home_primary_view.h",
"bookmark_home_tablet_ntp_controller.h",
"bookmark_home_tablet_ntp_controller.mm",
"bookmark_home_view_controller.h", "bookmark_home_view_controller.h",
"bookmark_home_view_controller.mm", "bookmark_home_view_controller.mm",
"bookmark_home_waiting_view.h", "bookmark_home_waiting_view.h",
...@@ -55,8 +120,6 @@ source_set("bookmarks") { ...@@ -55,8 +120,6 @@ source_set("bookmarks") {
"bookmark_promo_cell.mm", "bookmark_promo_cell.mm",
"bookmark_promo_controller.h", "bookmark_promo_controller.h",
"bookmark_promo_controller.mm", "bookmark_promo_controller.mm",
"bookmark_utils_ios.h",
"bookmark_utils_ios.mm",
"undo_manager_bridge_observer.h", "undo_manager_bridge_observer.h",
"undo_manager_bridge_observer.mm", "undo_manager_bridge_observer.mm",
"undo_manager_wrapper.h", "undo_manager_wrapper.h",
...@@ -110,9 +173,13 @@ source_set("bookmarks") { ...@@ -110,9 +173,13 @@ source_set("bookmarks") {
"//ui/gfx", "//ui/gfx",
"//url", "//url",
] ]
public_deps = [
":bookmarks_arc",
]
allow_circular_includes_from = [ allow_circular_includes_from = [
"//ios/chrome/browser/ui/bookmarks/bars", "//ios/chrome/browser/ui/bookmarks/bars",
"//ios/chrome/browser/ui/bookmarks/cells", "//ios/chrome/browser/ui/bookmarks/cells",
":bookmarks_arc",
] ]
libs = [ libs = [
"CoreGraphics.framework", "CoreGraphics.framework",
...@@ -121,13 +188,34 @@ source_set("bookmarks") { ...@@ -121,13 +188,34 @@ source_set("bookmarks") {
] ]
} }
source_set("unit_tests_arc") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"bookmark_utils_ios_unittest.mm",
]
deps = [
":bookmarks",
"//base",
"//components/bookmarks/browser",
"//components/bookmarks/test",
"//ios/chrome/browser",
"//ios/chrome/browser/bookmarks",
"//ios/chrome/browser/browser_state:test_support",
"//ios/web:test_support",
"//testing/gtest",
]
}
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
"bookmark_home_view_controller_unittest.mm", "bookmark_home_view_controller_unittest.mm",
"bookmark_ios_unittest.mm", "bookmark_ios_unittest.mm",
"bookmark_position_cache_unittest.mm", "bookmark_position_cache_unittest.mm",
"bookmark_utils_ios_unittest.mm", ]
public_deps = [
":unit_tests_arc",
] ]
deps = [ deps = [
":bookmarks", ":bookmarks",
......
...@@ -185,7 +185,7 @@ void CachePosition(CGFloat position, BookmarkMenuItem* item); ...@@ -185,7 +185,7 @@ void CachePosition(CGFloat position, BookmarkMenuItem* item);
// |model| must be loaded. // |model| must be loaded.
// |item| and |position| are out variables, only populated if the return is YES. // |item| and |position| are out variables, only populated if the return is YES.
BOOL GetPositionCache(bookmarks::BookmarkModel* model, BOOL GetPositionCache(bookmarks::BookmarkModel* model,
BookmarkMenuItem** item, BookmarkMenuItem* __autoreleasing* item,
CGFloat* position); CGFloat* position);
// Method exists for testing. // Method exists for testing.
void ClearPositionCache(); void ClearPositionCache();
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
#include "base/hash.h" #include "base/hash.h"
#include "base/i18n/string_compare.h" #include "base/i18n/string_compare.h"
#include "base/mac/bind_objc_block.h" #include "base/mac/bind_objc_block.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/mac/scoped_nsobject.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -36,6 +34,10 @@ ...@@ -36,6 +34,10 @@
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/models/tree_node_iterator.h" #include "ui/base/models/tree_node_iterator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using bookmarks::BookmarkNode; using bookmarks::BookmarkNode;
namespace bookmark_utils_ios { namespace bookmark_utils_ios {
...@@ -187,8 +189,7 @@ BOOL bookmarkMenuIsInSlideInPanel() { ...@@ -187,8 +189,7 @@ BOOL bookmarkMenuIsInSlideInPanel() {
UIView* dropShadowWithWidth(CGFloat width) { UIView* dropShadowWithWidth(CGFloat width) {
UIImage* shadowImage = [UIImage imageNamed:@"bookmark_bar_shadow"]; UIImage* shadowImage = [UIImage imageNamed:@"bookmark_bar_shadow"];
UIImageView* shadow = UIImageView* shadow = [[UIImageView alloc] initWithImage:shadowImage];
[[[UIImageView alloc] initWithImage:shadowImage] autorelease];
CGRect shadowFrame = CGRectMake(0, 0, width, 4); CGRect shadowFrame = CGRectMake(0, 0, width, 4);
shadow.frame = shadowFrame; shadow.frame = shadowFrame;
shadow.autoresizingMask = shadow.autoresizingMask =
...@@ -225,8 +226,8 @@ void CreateOrUpdateBookmarkWithUndoToast( ...@@ -225,8 +226,8 @@ void CreateOrUpdateBookmarkWithUndoToast(
} }
// Secondly, create an Undo group for all undoable actions. // Secondly, create an Undo group for all undoable actions.
base::scoped_nsobject<UndoManagerWrapper> wrapper( UndoManagerWrapper* wrapper =
[[UndoManagerWrapper alloc] initWithBrowserState:browser_state]); [[UndoManagerWrapper alloc] initWithBrowserState:browser_state];
// Create or update the bookmark. // Create or update the bookmark.
[wrapper startGroupingActions]; [wrapper startGroupingActions];
...@@ -260,8 +261,7 @@ void CreateOrUpdateBookmarkWithUndoToast( ...@@ -260,8 +261,7 @@ void CreateOrUpdateBookmarkWithUndoToast(
void PresentUndoToastWithWrapper(UndoManagerWrapper* wrapper, NSString* text) { void PresentUndoToastWithWrapper(UndoManagerWrapper* wrapper, NSString* text) {
// Create the block that will be executed if the user taps the undo button. // Create the block that will be executed if the user taps the undo button.
MDCSnackbarMessageAction* action = MDCSnackbarMessageAction* action = [[MDCSnackbarMessageAction alloc] init];
[[[MDCSnackbarMessageAction alloc] init] autorelease];
action.handler = ^{ action.handler = ^{
if (![wrapper hasUndoManagerChanged]) if (![wrapper hasUndoManagerChanged])
[wrapper undo]; [wrapper undo];
...@@ -302,8 +302,8 @@ void DeleteBookmarksWithUndoToast(const std::set<const BookmarkNode*>& nodes, ...@@ -302,8 +302,8 @@ void DeleteBookmarksWithUndoToast(const std::set<const BookmarkNode*>& nodes,
size_t nodeCount = nodes.size(); size_t nodeCount = nodes.size();
DCHECK_GT(nodeCount, 0u); DCHECK_GT(nodeCount, 0u);
base::scoped_nsobject<UndoManagerWrapper> wrapper( UndoManagerWrapper* wrapper =
[[UndoManagerWrapper alloc] initWithBrowserState:browser_state]); [[UndoManagerWrapper alloc] initWithBrowserState:browser_state];
// Delete the selected bookmarks. // Delete the selected bookmarks.
[wrapper startGroupingActions]; [wrapper startGroupingActions];
...@@ -354,8 +354,8 @@ void MoveBookmarksWithUndoToast(const std::set<const BookmarkNode*>& nodes, ...@@ -354,8 +354,8 @@ void MoveBookmarksWithUndoToast(const std::set<const BookmarkNode*>& nodes,
size_t nodeCount = nodes.size(); size_t nodeCount = nodes.size();
DCHECK_GT(nodeCount, 0u); DCHECK_GT(nodeCount, 0u);
base::scoped_nsobject<UndoManagerWrapper> wrapper( UndoManagerWrapper* wrapper =
[[UndoManagerWrapper alloc] initWithBrowserState:browser_state]); [[UndoManagerWrapper alloc] initWithBrowserState:browser_state];
// Move the selected bookmarks. // Move the selected bookmarks.
[wrapper startGroupingActions]; [wrapper startGroupingActions];
...@@ -404,38 +404,39 @@ void segregateNodes( ...@@ -404,38 +404,39 @@ void segregateNodes(
nodesSectionVector.clear(); nodesSectionVector.clear();
// Make a localized date formatter. // Make a localized date formatter.
base::scoped_nsobject<NSDateFormatter> formatter( NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[[NSDateFormatter alloc] init]);
[formatter setDateFormat:@"MMMM yyyy"]; [formatter setDateFormat:@"MMMM yyyy"];
// Segregate nodes by creation date. // Segregate nodes by creation date.
// Nodes that were created in the same month are grouped together. // Nodes that were created in the same month are grouped together.
for (auto* node : vector) { for (auto* node : vector) {
base::mac::ScopedNSAutoreleasePool pool; @autoreleasepool {
base::Time dateAdded = node->date_added(); base::Time dateAdded = node->date_added();
base::TimeDelta delta = dateAdded - base::Time::UnixEpoch(); base::TimeDelta delta = dateAdded - base::Time::UnixEpoch();
base::scoped_nsobject<NSDate> date( NSDate* date =
[[NSDate alloc] initWithTimeIntervalSince1970:delta.InSeconds()]); [[NSDate alloc] initWithTimeIntervalSince1970:delta.InSeconds()];
NSString* dateString = [formatter stringFromDate:date]; NSString* dateString = [formatter stringFromDate:date];
const std::string timeRepresentation = base::SysNSStringToUTF8(dateString); const std::string timeRepresentation =
base::SysNSStringToUTF8(dateString);
BOOL found = NO;
for (const auto& nodesSection : nodesSectionVector) { BOOL found = NO;
if (nodesSection->timeRepresentation == timeRepresentation) { for (const auto& nodesSection : nodesSectionVector) {
nodesSection->vector.push_back(node); if (nodesSection->timeRepresentation == timeRepresentation) {
found = YES; nodesSection->vector.push_back(node);
break; found = YES;
break;
}
} }
}
if (found) if (found)
continue; continue;
// No NodesSection found. // No NodesSection found.
auto nodesSection = base::MakeUnique<NodesSection>(); auto nodesSection = base::MakeUnique<NodesSection>();
nodesSection->time = dateAdded; nodesSection->time = dateAdded;
nodesSection->timeRepresentation = timeRepresentation; nodesSection->timeRepresentation = timeRepresentation;
nodesSection->vector.push_back(node); nodesSection->vector.push_back(node);
nodesSectionVector.push_back(std::move(nodesSection)); nodesSectionVector.push_back(std::move(nodesSection));
}
} }
// Sort the NodesSections. // Sort the NodesSections.
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
#include "testing/gtest_mac.h" #include "testing/gtest_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using bookmarks::BookmarkNode; using bookmarks::BookmarkNode;
namespace { namespace {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment