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

Side by Side Diff: base/android/java/src/org/chromium/base/NonThreadSafe.java

Issue 2548013002: Remove redundant field initialization in Java code. (Closed)
Patch Set: rebase Created 4 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 package org.chromium.base; 5 package org.chromium.base;
6 6
7 import org.chromium.base.annotations.SuppressFBWarnings; 7 import org.chromium.base.annotations.SuppressFBWarnings;
8 8
9 /** 9 /**
10 * NonThreadSafe is a helper class used to help verify that methods of a 10 * NonThreadSafe is a helper class used to help verify that methods of a
11 * class are called from the same thread. 11 * class are called from the same thread.
12 */ 12 */
13 public class NonThreadSafe { 13 public class NonThreadSafe {
14 private Long mThreadId = null; 14 private Long mThreadId;
15 15
16 public NonThreadSafe() { 16 public NonThreadSafe() {
17 ensureThreadIdAssigned(); 17 ensureThreadIdAssigned();
18 } 18 }
19 19
20 /** 20 /**
21 * Changes the thread that is checked for in CalledOnValidThread. This may 21 * Changes the thread that is checked for in CalledOnValidThread. This may
22 * be useful when an object may be created on one thread and then used 22 * be useful when an object may be created on one thread and then used
23 * exclusively on another thread. 23 * exclusively on another thread.
24 */ 24 */
(...skipping 10 matching lines...) Expand all
35 @SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD") 35 @SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD")
36 public synchronized boolean calledOnValidThread() { 36 public synchronized boolean calledOnValidThread() {
37 ensureThreadIdAssigned(); 37 ensureThreadIdAssigned();
38 return mThreadId.equals(Thread.currentThread().getId()); 38 return mThreadId.equals(Thread.currentThread().getId());
39 } 39 }
40 40
41 private void ensureThreadIdAssigned() { 41 private void ensureThreadIdAssigned() {
42 if (mThreadId == null) mThreadId = Thread.currentThread().getId(); 42 if (mThreadId == null) mThreadId = Thread.currentThread().getId();
43 } 43 }
44 } 44 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698