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

Side by Side Diff: ui/base/clipboard/clipboard_android.cc

Issue 2901143002: Remove entry from map_ of ClipboardMap when jstr is null or empty (Closed)
Patch Set: remove entry from map Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/base/clipboard/clipboard_android.h" 5 #include "ui/base/clipboard/clipboard_android.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 Java_Clipboard_clear(env, clipboard_manager_); 177 Java_Clipboard_clear(env, clipboard_manager_);
178 map_state_ = MapState::kUpToDate; 178 map_state_ = MapState::kUpToDate;
179 sequence_number_++; 179 sequence_number_++;
180 UpdateLastModifiedTime(base::Time::Now()); 180 UpdateLastModifiedTime(base::Time::Now());
181 } 181 }
182 182
183 void ClipboardMap::SetLastModifiedTimeWithoutRunningCallback(base::Time time) { 183 void ClipboardMap::SetLastModifiedTimeWithoutRunningCallback(base::Time time) {
184 last_modified_time_ = time; 184 last_modified_time_ = time;
185 } 185 }
186 186
187 // Add a key:jstr pair to map, but only if jstr is not null, and also 187 // Add a key:jstr pair to map, if jstr is null or is empty, then remove that
188 // not empty. 188 // entry.
189 void AddMapEntry(JNIEnv* env, 189 void AddMapEntry(JNIEnv* env,
190 std::map<std::string, std::string>* map, 190 std::map<std::string, std::string>* map,
191 const char* key, 191 const char* key,
192 const ScopedJavaLocalRef<jstring>& jstr) { 192 const ScopedJavaLocalRef<jstring>& jstr) {
193 if (!jstr.is_null()) { 193 if (jstr.is_null()) {
194 std::string str = ConvertJavaStringToUTF8(env, jstr.obj()); 194 map->erase(key);
195 if (!str.empty()) 195 return;
196 (*map)[key] = str; 196 }
197 std::string str = ConvertJavaStringToUTF8(env, jstr.obj());
198 if (!str.empty()) {
199 (*map)[key] = str;
200 } else {
201 map->erase(key);
197 } 202 }
198 } 203 }
199 204
200 void ClipboardMap::UpdateLastModifiedTime(base::Time time) { 205 void ClipboardMap::UpdateLastModifiedTime(base::Time time) {
201 last_modified_time_ = time; 206 last_modified_time_ = time;
202 // |modified_callback_| may be null in tests. 207 // |modified_callback_| may be null in tests.
203 if (modified_cb_) 208 if (modified_cb_)
204 modified_cb_.Run(time); 209 modified_cb_.Run(time);
205 } 210 }
206 211
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 return RegisterNativesImpl(env); 554 return RegisterNativesImpl(env);
550 } 555 }
551 556
552 // Returns a pointer to the current ClipboardAndroid object. 557 // Returns a pointer to the current ClipboardAndroid object.
553 static jlong Init(JNIEnv* env, 558 static jlong Init(JNIEnv* env,
554 const base::android::JavaParamRef<jobject>& obj) { 559 const base::android::JavaParamRef<jobject>& obj) {
555 return reinterpret_cast<intptr_t>(Clipboard::GetForCurrentThread()); 560 return reinterpret_cast<intptr_t>(Clipboard::GetForCurrentThread());
556 } 561 }
557 562
558 } // namespace ui 563 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698